From a9181df87d78828318f2e9f8d4ea012bc06883b9 Mon Sep 17 00:00:00 2001 From: Bruno Victal Date: Thu, 7 Sep 2023 16:51:23 +0100 Subject: [PATCH 3/3] Fix double-free when requesting MediaBox. Explicitly close the Ghostscript PDF interpreter before calling quit. References: [1]: [2]: --- src/u_ghostscript.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/u_ghostscript.c b/src/u_ghostscript.c index 5974b31..d14674f 100644 --- a/src/u_ghostscript.c +++ b/src/u_ghostscript.c @@ -317,10 +317,10 @@ gsexe(FILE **out, bool *isnew, char *exenew, char *exeold) * Call ghostscript to extract the /MediaBox from the pdf given in file. * Command line, for gs >= 9.50, * gs -q -dNODISPLAY --permit-file-read=in.pdf -c \ - * "(in.pdf) (r) file runpdfbegin 1 pdfgetpage /MediaBox pget pop == quit" + * "(in.pdf) (r) file runpdfbegin 1 pdfgetpage /MediaBox pget pop == runpdfend quit" * gs < 9.50: * gs -q -dNODISPLAY -dNOSAFER -c \ - * "(in.pdf) (r) file runpdfbegin 1 pdfgetpage /MediaBox pget pop == quit" + * "(in.pdf) (r) file runpdfbegin 1 pdfgetpage /MediaBox pget pop == runpdfend quit" * The command line was found, and modified a bit, at *https://stackoverflow.com/questions/2943281/using-ghostscript-to-get-page-size * Beginning with gs 9.50, "-dSAFER" is the default, and permission to access @@ -349,9 +349,11 @@ gsexe_mediabox(char *file, int *llx, int *lly, int *urx, int *ury) return -3; exenew = "%s -q -dNODISPLAY \"--permit-file-read=%s\" -c \"(%s) (r) " - "file runpdfbegin 1 pdfgetpage /MediaBox pget pop == quit\""; + "file runpdfbegin 1 pdfgetpage /MediaBox pget pop == " + "runpdfend quit\""; exeold = "%s -q -dNODISPLAY -c \"(%s) (r) " - "file runpdfbegin 1 pdfgetpage /MediaBox pget pop == quit\""; + "file runpdfbegin 1 pdfgetpage /MediaBox pget pop == " + "runpdfend quit\""; /* malloc() buffers for the command line, if necessary */ fmt = exenew; @@ -445,7 +447,8 @@ gslib_mediabox(char *file, int *llx, int *lly, int *urx, int *ury) argnew[3] = "--permit-file-read=%s"; /* file */ argnew[4] = "-c"; argnew[5] = - "(%s) (r) file runpdfbegin 1 pdfgetpage /MediaBox pget pop == quit"; + "(%s) (r) file runpdfbegin 1 pdfgetpage /MediaBox pget pop == " + "runpdfend quit"; argold[0] = argnew[0]; argold[1] = argnew[1]; -- 2.40.1 Guix in a profile....* guix/scripts/pull.scm (%pull-version): New variable. (build-from-source): Pass #:pull-version to BUILD. (whole-package-for-legacy, derivation->manifest-entry): New procedure. (build-and-install): Rewrite in terms of 'build-and-use-profile'. * guix/scripts/system.scm (maybe-suggest-running-guix-pull)[latest]: Switch to "/current". * scripts/guix.in (augment-load-paths!): Remove use of ~/.config/guix/latest. * build-aux/compile-as-derivation.scm: Replace "/guix/latest/" with "/current/share/guile/site/X.Y" * guix/scripts.scm (warn-about-old-distro)[age]: Check "/current" instead of "/latest". * doc/guix.texi (Invoking guix pull): Document it. * doc/contributing.texi (Running Guix Before It Is Installed): Remove footnote about abusing ~/.config/guix/latest. Ludovic Courtès 2018-01-28guix: Let Emacs detect “scripts/guix.in” appropriate mode....Since commit 6f774d481839f87178c5895ac2d661e141f879b8 which introduces the use of Guile's meta switch in “scripts/guix.in”, Emacs was not using ‘scheme-mode’ for this file. * scripts/guix.in: Replace "-*- scheme -*-" with a local variable. Signed-off-by: Ludovic Courtès <ludo@gnu.org> Mathieu Lirzin 2018-01-23guix: Refactor script....* scripts/guix.in: Remove empty surrounding ‘let’. Define 'main' as the procedure called when running the script. (maybe-augment-load-paths!): Rename to ... (augment-load-paths!): ... this. Use 'and=>' for 'file-exists?'. (run-guix-main): Rename to ... (main): ... this. Call 'augment-load-paths!'. Signed-off-by: Ludovic Courtès <ludo@gnu.org> Mathieu Lirzin 2018-01-23build: Expand ‘scripts/guix’ at Make time....This moves the complexity of Autotools variable expansion outside of the application code. * scripts/guix.in (config-lookup): Delete. (maybe-augment-load-paths!, run-guix-main): Use fully expanded variables instead of calling ‘config-lookup’. * configure.ac: Don't use AC_CONFIG_FILES for ‘scripts/guix’. Use AC_PROG_SED. * Makefile.am (scripts/guix): New rule. (do_subst): New variable. (CLEANFILES, EXTRA_DIST): Adapt. Co-authored-by: Ludovic Courtès <ludo@gnu.org> Mathieu Lirzin