Repository navigation
Conversation
The binary data after an inline image's ID was read as tokens, so an
unbalanced "(" in it opened a string that swallowed the rest of the
page, and other bytes counted as malformed operands. Interpret now skips
the data up to the first EI between whitespace, and its callers still
see the ID and EI operators. This is only a skip: it leaves room for
parsing the image dictionary and data, as upstream PR ledongthuc#89 proposes.
The binary data after an inline image's ID was read as tokens, so an
unbalanced "(" in it opened a string that swallowed the rest of the
page, and other bytes counted as malformed operands. Interpret now skips
the data up to the first EI between whitespace, and its callers still
see the ID and EI operators. This is only a skip: it leaves room for
parsing the image dictionary and data, as upstream PR ledongthuc#89 proposes.
The binary data after an inline image's ID was read as tokens, so an
unbalanced "(" in it opened a string that swallowed the rest of the
page, and other bytes counted as malformed operands. Interpret now skips
the data up to the first EI between whitespace, and its callers still
see the ID and EI operators. This is only a skip: it leaves room for
parsing the image dictionary and data, as upstream PR ledongthuc#89 proposes.
|
Thank you for this contribution. Inline image support is useful. Some problems must be fixed before this PR can be merged.
The function readInlineImage in lex.go does not stop if it does not find EI. At the end of the data, readByte returns '\n' again and again. The loop runs forever and the memory use increases. Interpret calls this function, so one invalid content stream stops text extraction. To reproduce, use these content streams:
The loop must stop at the end of the stream. It must return an error in this case.
The code searches for \nEI followed by a space or a newline. This causes two problems:
Also, unreadByte is called four times. This can give the wrong result when the buffer reloads. Use the image size to find the end of the data. The size comes from W, H, BPC and CS when the data is not filtered. If you cannot use the size, limit the search to the stream length.
lex.go has fmt.Printf("DEBUG: ..."). Remove this line. Library code must not write to standard output.
Add unit tests for these cases:
A test with a real PDF that has an inline image would also help. The example in the description uses 99.pdf, which is not in the repository. Other comments RawBytes is clear and matches RawString. No change is needed. Please reply when you update the PR. Thank you. |
|
@ledongthuc Your review is so careful that it makes me ashamed. I made a lot of mistakes. I've updated the code. Here are the changes:
|
Close: #30
Saving image data as string because I don't want to break current API.
Add
Value.RawBytesfor getting image data conveniently.An example of extracting inline image from 99.pdf: