Bug 706940

Summary: Dereference of free object; can't embed LibertinusSans-Bold
Product: Ghostscript Reporter: Karl Berry <karl>
Component: PDF InterpreterAssignee: Default assignee <ghostpdl-bugs>
Status: RESOLVED INVALID    
Severity: normal    
Priority: P4    
Version: 10.01.2   
Hardware: PC   
OS: Linux   
Customer: Word Size: ---
Attachments: doc.pdf input file

Description Karl Berry 2023-07-25 16:20:48 UTC
Created attachment 24601 [details]
doc.pdf input file

With attached doc.pdf, running (gs 10.01.2, compiled from original source, GNU/Linux x86_64)

gs -q -dNOPAUSE -DBATCH -sDEVICE=pdfwrite -sOutputFile=out.pdf doc.pdf

results in

Dereference of free object 149, next object number as offset failed, returning NULL object.                                                                    
GPL Ghostscript 10.01.2: Can't embed the complete font QMNCHZ+LibertinusSans-Bold as it is too large, embedding a subset.         

The output looks ok at first blush, but evidently something must be awry.

I get the same error messages with 9.56.1 and 9.20.

Sorry, my attempts to cut down the input pdf made the problem go away.

Thanks,
Karl
Comment 1 Ken Sharp 2023-07-25 18:10:10 UTC
The PDF file has an xref which contains this line at index 149:

0000000162 00256 f 

So that means object 149 can be found at offset 162, has a generation number of 256 and is a free object.

There is no object 149 in the file and there is no object at offset 162, that is the middle of object 4, which is an annotation. The object is, however, referenced in the file by object 134:

134 0 obj
<<
  /S /Transparency
  /CS 149 0 R
>>
endobj

and object 134 is used by a Form XObject:

122 0 obj
<<
  /Type /XObject
  /Subtype /Form
  /FormType 1
  /PTEX.FileName (./img/shadowbox.pdf)
  /PTEX.PageNumber 1
  /PTEX.InfoDict 137 0 R
  /BBox [ 0 0 292 151 ]
  /Group 134 0 R

That From is used by a Resources Dictionary:

130 0 obj
<<
  /Font <<
...
  >>
  /XObject <<
    /Fm2 121 0 R
    /Im9 122 0 R

Which is used by the Page object 131:

131 0 obj
<<
  /Type /Page
  /Contents 132 0 R
  /Resources 130 0 R

Which is page #6 in the Pages tree.

So in summary; yes something is awry. It's your PDF file. There is also a separate error in a pattern.

Just because Ghostscript tells you there is a problem with your PDF file, and other consumers don't, doesn't mean Ghostscript has a bug.

The warning about embedding the font is a different issue altogether and is probably due to the size of the font (doesn't look like it has been subset at all). Ghostscript embeds a subset font in the output and I imagine it works correctly.

I don't actually see any bug here, except the knackered input file.
Comment 2 Karl Berry 2023-07-25 19:47:42 UTC
Thanks much for the analysis, and sorry for the noise.