pdf-lib icon indicating copy to clipboard operation
pdf-lib copied to clipboard

Make stream parser resilient to text in streams

Open Trapfether opened this issue 3 years ago • 1 comments

What?

Updates the streamParser to ignore the keyword 'stream' if it is not proceeded by a special character. Fixes #1206

Why?

Some font files when embedded include their license information, one font where this occurred included the word 'bitstream' several times which confused the streamParser. The streamParser thought there were more open streams than there were.

How?

The word 'stream' should be proceeded by a space, newline, carriage return, backslash, lessThan, or greaterThan character. I also included tabs for good measure. If the word 'stream' is not proceeded by one of those characters, it is ignored.

There is a special case just after a 'stream' is consumed, we set a flag that allows an immediately following 'stream' to be counted.

Testing?

I added a test to the testing suite that exercised the fail condition with the current parser, then updated the parser to pass the new test.

New Dependencies?

NA

Screenshots

NA

Suggested Reading?

NA

Anything Else?

NA

Checklist

  • [X] I read CONTRIBUTING.md.
  • [X] I read MAINTAINERSHIP.md#pull-requests.
  • [X] I added/updated unit tests for my changes.
  • [ ] I added/updated integration tests for my changes.
  • [X] I ran the integration tests.
  • [X] I tested my changes in Node, Deno, and the browser.
  • [X] I viewed documents produced with my changes in Adobe Acrobat, Foxit Reader, Firefox, and Chrome.
  • [X] I added/updated doc comments for any new/modified public APIs.
  • [X] My changes work for both new and existing PDF files.
  • [X] I ran the linter on my changes.

Trapfether avatar Apr 16 '22 01:04 Trapfether

I have tested this change out in a forked version of the repo and can confirm that the change works as intended. Look forward to this being reviewed and then released so that my organisation can revert back to this repo.

ahaganDEV avatar Jul 19 '22 14:07 ahaganDEV