Bug 708244

Summary: pdfmark error
Product: Ghostscript Reporter: Luigi Scarso <luigi.scarso>
Component: PDF WriterAssignee: Default assignee <ghostpdl-bugs>
Status: RESOLVED DUPLICATE    
Severity: normal    
Priority: P2    
Version: 10.04.0   
Hardware: PC   
OS: Linux   
Customer: Word Size: ---

Description Luigi Scarso 2025-01-11 08:47:26 UTC
With
https://www.lscarso.me/luatex/notation.pdf

(72MBytes, I will remove it once the bug is closed)

running
/opt/ghostscript/ghostscript-10.04.0/BUILD/bin/gs -dPDFSTOPONWARNING -dPDFSTOPONERROR -dPDFDEBUG -dNOPAUSE -sDEVICE=pdfwrite -dCompressPages=false -dCompressStreams=false -sOutputFile=z.pdf notation.pdf  -c quit &>z10.out


gives
GPL Ghostscript 10.04.0 (2024-09-18)
Copyright (C) 2024 Artifex Software, Inc.  All rights reserved.
This software is supplied under the GNU AGPLv3 and comes with NO WARRANTY:
see the file COPYING for details.
% Reading header
:
4469 0 obj
 (<FE><FF>^@') endobj
 4470 0 obj
 <<
 /S /GoTo /D (idx.(.IDX6)
 >>
 endobj
Error: /undefined in --runpdf--
Operand stack:
   --nostringval--   --nostringval--   --nostringval--   --nostringval--
Execution stack:
   %interp_exit   .runexec2   --nostringval--   runpdf   --nostringval--   2   %stopped_push   --nostringval--   runpdf   runpdf   false   1   %stopped_push   1933   1   3   %oparray_pop   1932   1   3   %oparray_pop   1917   1   3   %oparray_pop   1918   1   3   %oparray_pop   runpdf   runpdf   runpdf   runpdf
Dictionary stack:
   --dict:744/1123(ro)(G)--   --dict:0/20(G)--   --dict:86/200(L)--   --dict:6/10(L)--
Current allocation mode is local
GPL Ghostscript 10.04.0: Unrecoverable error, exit code 1
GPL Ghostscript 10.04.0: Page object was reserved for an Annotation destination, but no such page was drawn, annotation in output will be invalid.
:
GPL Ghostscript 10.04.0: Page object was reserved for an Annotation destination, but no such page was drawn, annotation in output will be invalid.
GPL Ghostscript 10.04.0: ERROR: A pdfmark destination page 919 points beyond the last page 1.

This looks suspiciuos
 /S /GoTo /D (idx.(.IDX6)

(unbalaced '(' in a literal string)


gs 9.55 gives:

GPL Ghostscript 9.55.0 (2021-09-27)
Copyright (C) 2021 Artifex Software, Inc.  All rights reserved.
This software is supplied under the GNU AGPLv3 and comes with NO WARRANTY:
see the file COPYING for details.
:
%Resolving: [4470 0]
<<
/S /GoTo /D (idx.\(.IDX6) >>

where '(' is correctly escaped.

The pdf seems to be fine with acrobat reader 2024.005.20320

--
luigi
Comment 1 Ken Sharp 2025-01-11 09:47:34 UTC
(In reply to Luigi Scarso from comment #0)
> With
> https://www.lscarso.me/luatex/notation.pdf
> 
> (72MBytes, I will remove it once the bug is closed)

We need all files to be attached to Bugzilla. This is our reference for the future, and we cannot have example files disappearing. If the file is too large please try and find or create a smaller one.

Also, the Title says the problem is a 'pdrfmark error', but PDF files cannot contain pdfmark operations (pdfmark is a PostScript operator). So either the problem isn't a pdfmark, or the title is incorrect.


> gives
> GPL Ghostscript 10.04.0 (2024-09-18)
> Copyright (C) 2024 Artifex Software, Inc.  All rights reserved.
> This software is supplied under the GNU AGPLv3 and comes with NO WARRANTY:
> see the file COPYING for details.
> % Reading header
> :
> 4469 0 obj
>  (<FE><FF>^@') endobj
>  4470 0 obj
>  <<
>  /S /GoTo /D (idx.(.IDX6)
>  >>
>  endobj
> Error: /undefined in --runpdf--

And indeed, that is not a pdfmark.


> This looks suspiciuos
>  /S /GoTo /D (idx.(.IDX6)
> 
> (unbalaced '(' in a literal string)
> 
> 
> gs 9.55 gives:
> 
> GPL Ghostscript 9.55.0 (2021-09-27)
> Copyright (C) 2021 Artifex Software, Inc.  All rights reserved.
> This software is supplied under the GNU AGPLv3 and comes with NO WARRANTY:
> see the file COPYING for details.
> :
> %Resolving: [4470 0]
> <<
> /S /GoTo /D (idx.\(.IDX6) >>
> 
> where '(' is correctly escaped.

So... The problem is that the PDF file is invalid ? Indeed the two PDF files you are using seem to be different.
Comment 2 Luigi Scarso 2025-01-11 10:54:29 UTC
The problem is quite simple:
running
/opt/ghostscript/ghostscript-10.04.0/BUILD/bin/gs -dPDFSTOPONWARNING -dPDFSTOPONERROR -dPDFDEBUG -dNOPAUSE -sDEVICE=pdfwrite -dCompressPages=false -dCompressStreams=false -sOutputFile=z.pdf notation.pdf  -c quit &>z10.out

gives an error.


The last 2 lines of the stdin+stderr outputs redirected to z10.out says:
"""
GPL Ghostscript 10.04.0: Page object was reserved for an Annotation destination, but no such page was drawn, annotation in output will be invalid.
GPL Ghostscript 10.04.0: ERROR: A pdfmark destination page 919 points beyond the last page 1.
"""

So: 
Product: Ghostscript, 
Component: PDF Writer,
and the title report an error marked with "ERROR" about this Product/Component.
I don't know if the problem is the pdfmark or not, but this what gs seems to sa says.


About
"""
The pdf seems to be fine with acrobat reader 2024.005.20320
"""

Of course I am talking of notation.pdf (the only file I am using), because the OutoputFile z.pdf it completely invalid .

I am not sure if I can make a smaller example quickly.

--
luigi
Comment 3 Ken Sharp 2025-01-11 11:58:26 UTC
(In reply to Luigi Scarso from comment #0)

> gives
> GPL Ghostscript 10.04.0 (2024-09-18)
> Copyright (C) 2024 Artifex Software, Inc.  All rights reserved.
> This software is supplied under the GNU AGPLv3 and comes with NO WARRANTY:
> see the file COPYING for details.
> % Reading header
> :
> 4469 0 obj
>  (<FE><FF>^@') endobj
>  4470 0 obj
>  <<
>  /S /GoTo /D (idx.(.IDX6)
>  >>
>  endobj
> Error: /undefined in --runpdf--

The reason you get an error, I very strongly suspect, is because you have set PDFSTOPONWARNING, and without that the file **actually** generates a warning and continues, but results in truncated Outlines.

So the error is to be expected, it's what you asked for.

The PDFDEBUG output is entirely correct, but note that the output of PDFDEBUG with the new PDF interpreter is not the same as the output with the old PDF interpreter; the lack of an escape character for the parentheses is not indicative of an error.

I very much suspect that this is, basically, a duplicate of bug #708234 but you haven't quoted the output when you **don't** set PDFSTOPONWARNING and PDFDEBUG.

The bug in 708234 is due to the original file having an error; there's a node in the Names Dests tree which contains entries in the Names array which are outside the  Limits values, which means they are not found when we try to find a named destination. Because they are not found this causes an error trying to write the named destination resulting in part of the Outlines going missing in the output file.

I looked at the file supplied with 708234 and that contains a similar looking entry in the Outlines:

45215 0 obj
<<
  /Names [ (idx.U.IDX93) 4849 0 R (idx.V.IDX45) 4653 0 R (idx.V.IDX94) 
    4853 0 R (idx.W.IDX46) 4657 0 R (idx.W.IDX95) 4857 0 R (idx.X.IDX47) 
    4661 0 R (idx.X.IDX96) 4861 0 R (idx.[.IDX17) 4540 0 R (idx.[.IDX64) 
    4732 0 R (idx.\(.IDX53) 4688 0 R (idx.\(.IDX6) 4496 0 R (idx.\).IDX54) 
    4692 0 R (idx.\).IDX7) 4500 0 R (idx.\.IDX18) 4545 0 R (idx.\.IDX65) 
    4736 0 R (idx.].IDX19) 4549 0 R (idx.].IDX66) 4740 0 R (idx.^.IDX20) 
    4553 0 R (idx.^.IDX67) 4745 0 R (idx._.IDX21) 4557 0 R (idx._.IDX68) 
    4749 0 R (idx.|.IDX22) 4561 0 R (idx.|.IDX69) 4753 0 R (idx.~.IDX23) 
    4565 0 R (idx.~.IDX70) 4757 0 R (paper variables concerning headers and markups) 
    2166 0 R (paper variables for debugging) 2167 0 R (paper variables for line breaking) 
    2163 0 R (paper variables for page breaking) 2164 0 R (paper variables for page numbering) 
    2165 0 R (paper variables for shifts and indents) 2161 0 R 
    (paper variables for two-sided mode) 2160 0 R ]
  /Limits [ (idx.U.IDX93) (paper variables for two-sided mode) ]
>>
endobj

Note the lower Limit is 'idx.U.IDX93, however it also contains a number of entries in the Names array which are lexically earlier than 'U'. This includes the '(' of 'idx.\(.IDX6' but also the ')', '[', and ']' characters. There may be others, I have not checked.

As I said to Werner in bug #708234, I could see other entries in the Dests tree with the same problem, this is one of them.


> The pdf seems to be fine with acrobat reader 2024.005.20320

The fact that Acrobat opens a file without complaint is not, sadly, an indication that the file is completely valid. Acrobat ignores many broken elements of PDF files without bothering to mention it.

As I mentioned to Werner on bug #708234; Acrobat displays the Named destination (page x11, A.12.6, 'Instrument-specific markup') but clicking it has no effect. I imagine the same would be true for the named destination in your file.

If you think this is not a duplicate of the same problem (bug in the input file) then please reopen the bug, but you will need to find some way to attach the input file here.

*** This bug has been marked as a duplicate of bug 708234 ***
Comment 4 Ken Sharp 2025-01-11 12:02:17 UTC
(In reply to Luigi Scarso from comment #2)
> The problem is quite simple:
> running
> /opt/ghostscript/ghostscript-10.04.0/BUILD/bin/gs -dPDFSTOPONWARNING
> -dPDFSTOPONERROR -dPDFDEBUG -dNOPAUSE -sDEVICE=pdfwrite
> -dCompressPages=false -dCompressStreams=false -sOutputFile=z.pdf
> notation.pdf  -c quit &>z10.out
> 
> gives an error.

Of course it does, you asked it to give you an error when it would normally produce a warning.


> The last 2 lines of the stdin+stderr outputs redirected to z10.out says:
> """
> GPL Ghostscript 10.04.0: Page object was reserved for an Annotation
> destination, but no such page was drawn, annotation in output will be
> invalid.
> GPL Ghostscript 10.04.0: ERROR: A pdfmark destination page 919 points beyond
> the last page 1.
> """

Those are irrelevant, they come from the pdfwrite device and are due to the fact that the input was terminated.


> About
> """
> The pdf seems to be fine with acrobat reader 2024.005.20320
> """

I doubt it really is, as per my comment #3.

 
> Of course I am talking of notation.pdf (the only file I am using), because
> the OutoputFile z.pdf it completely invalid .

If you throw an error instead of completing the output, yes naturally the outptu file will not be valid.

 
> I am not sure if I can make a smaller example quickly.

Well if you believe my comment #3 is not correct, then you will need to find some way to make a smaller example, or compress the input, or something.
Comment 5 Luigi Scarso 2025-01-11 15:48:05 UTC
(In reply to Ken Sharp from comment #4)
> Well if you believe my comment #3 is not correct, then you will need to find
> some way to make a smaller example, or compress the input, or something.

Your comment #3 is correct, the bug is closed and I have deleted the file
(although I don't exclude that I can put a new version, I'm working on a patch on my side)

--
luigi