-
-
Notifications
You must be signed in to change notification settings - Fork 40
Fix invalid stream ending #122
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
base: main
Are you sure you want to change the base?
Conversation
src/PDFObjectParser.php
Outdated
| } | ||
| $stream_content .= $this->_c; | ||
| /// Get /Length from parsed dict | ||
| $length = $obj['Length']->get_int(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this code fails in some cases, because Length key does not appear in some cases; so $obj['Length'] is null and it raises an exception
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would be your suggestion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to debug why the existing solution does not work and try to fix the issue in the appropriate function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried just advancing the position and it seems to work, can you confirm?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't tested it yet because I'm not currently in front of my computer, but following the code, it looks very good. It would be nice if anyone could test it, apart from me. If not, I will test it in a few hours
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be better to use length if it exists and guess if it doesn't.
Is a false positive possible when searching for endings?
| } else if (preg_match('/endobj\s$/', $this->_buffer->substratpos(7))) { | ||
| $stream_content .= $this->_c; | ||
| $this->nextchar(); | ||
| break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works for me,
it makes sense, because it does a break and the next ->nextChar() of the while loop is never executed.
Please release it
Alternative for #120,
without guessing(#120 (comment), #120 (comment))endstreamThis PR adds support for PDF streams where the end tokens(like
endstream) appear immediately after the stream data, without any whitespace or line break.Some PDF generators embed metadata blocks that end like this:
In this case, the parser previously failed to recognize the
endstreamtoken because it expected a whitespace separator before it. As a result, the tokenization would break and parsing of the stream would fail.