Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid reference in stream "Length" causes endless parsing #856

Closed
fancycode opened this issue Apr 24, 2024 · 0 comments · Fixed by #857
Closed

Invalid reference in stream "Length" causes endless parsing #856

fancycode opened this issue Apr 24, 2024 · 0 comments · Fixed by #857
Assignees

Comments

@fancycode
Copy link
Contributor

Unfortunately I can't share the document, but here are some information on the problem:

  • PDF is about 150 MBytes
  • One of the streams has a Length entry that references another object.
<< ... /Length 880 0 R ... >>
  • The referenced object 880 has this entry in the xref table (i.e. it's marked as free):
0000001044 00000 f
  • The referenced object 880 is not in the PDF and the position 1044 points into the stream data of another object.

When parsing the stream, the length is parsed with

if sd.StreamLength, err = int64Object(c, ctx, *sd.StreamLengthObjNr); err != nil {

i, err := dereferencedInteger(c, ctx, objNr)

o, err := dereferencedObject(c, ctx, objNr)

o, err := ParseObjectWithContext(c, ctx, *entry.Offset, objNr, *entry.Generation)

Now, the (invalid) offset is used to parse the object

if rd, err = newPositionedReader(ctx.Read.RS, &offset); err != nil {

and the loop in

for endInd < 0 && streamInd < 0 {

never terminates. It reads the file in 1024 byte increments but doesn't terminate after a couple of minutes when I cancelled it.

My suggestion is to ignore the missing Length reference and fix the stream length in

if fixLength || l != *sd.StreamLength {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants