Bug 705855

Summary: Double-free when requesting MediaBox
Product: Ghostscript Reporter: Till Kamppeter <till.kamppeter>
Component: PDF InterpreterAssignee: Default assignee <ghostpdl-bugs>
Status: RESOLVED DUPLICATE    
Severity: normal    
Priority: P4    
Version: 9.56.1   
Hardware: PC   
OS: Linux   
Customer: Word Size: ---
Attachments: cross.pdf

Description Till Kamppeter 2022-09-08 09:58:47 UTC
Created attachment 23126 [details]
cross.pdf

If I run the command line

gs -q -dNODISPLAY --permit-file-read=tests/data/cross.pdf -c "(tests/data/cross.pdf) (r) file runpdfbegin 1 pdfgetpage /MediaBox pget pop == quit"

I get

[-0.2 -0.9 72.2 72.8]
free(): double free detected in tcache 2
Aborted (core dumped)

whereas

gs -q -dNODISPLAY -dNOSAFER -c "(tests/data/cross.pdf) (r) file runpdfbegin 1 pdfgetpage /MediaBox pget pop == quit"

has no double-free and gives:

[-0.2 -0.9 72.2 72.8]

Ghostscript version is 9.56.1.

The problem occurs with any PDF file but I attach cross.pdf anyway.
Comment 1 Ken Sharp 2022-09-08 10:11:48 UTC
As noted in bug report 705836; if you are going to initialise the PDF interpreter (using runpdfbegin) then you should terminate it before exit (using runpdfend). Doing so will, almost certainly, solve your problem with 9.56.1.

As noted in 705836, this has been fixed in current code, you may like to try the 10.00.0 release candidate.

*** This bug has been marked as a duplicate of bug 705836 ***
Comment 2 Till Kamppeter 2022-09-08 11:07:22 UTC
One additional question:

The command line shown in the initial posting is from the test suite of xfig. Does such a command line still work in 10.00.0? Does it require the PostScript incarnation of the PDF interpreter?
Comment 3 Ken Sharp 2022-09-08 11:20:01 UTC
(In reply to Till Kamppeter from comment #2)

> The command line shown in the initial posting is from the test suite of
> xfig. Does such a command line still work in 10.00.0? Does it require the
> PostScript incarnation of the PDF interpreter?

Since it is running PostScript yes, obviously, it requires the PostScript interpreter.

Can you get the MediaBox without using the PostScript interpreter ? Yes, you can use the -dPDFINFO switch. This works with both Ghostscript and GhostPDF and is documented in the 10.00.0 release.

It does not produce the information in the same format as your original PostScript program. If you require that specific format then you're going to have to script the interpreter which mean writing a program, which means using PostScript and therefore the PostScript interpreter.