Skip to content

Reading inline image data is incorrectly implemented [BUG] #11124

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

Closed
misos1 opened this issue Sep 6, 2019 · 0 comments · Fixed by #12028
Closed

Reading inline image data is incorrectly implemented [BUG] #11124

misos1 opened this issue Sep 6, 2019 · 0 comments · Fixed by #12028

Comments

@misos1
Copy link

misos1 commented Sep 6, 2019

Attach (recommended) or Link to PDF file here:

bi.pdf

Along these lines in https://github.com/mozilla/pdf.js/blob/master/src/core/parser.js:

  makeInlineImage(cipherTransform) {
...
    this.buf2 = Cmd.get('EI'); 

I suppose it simply searches for "EI" sequence separated by whitespaces. But that is not enough. It is needed to calculate size of decoded image data from parameters like width, height, bit per component and color space. Then decode data and see for EOD or look for exactly right number of decoded bytes and then stop parsing image data as not every filter has EOD.

This is content stream from attached pdf:

100 0 0 100 0 0 cm
BI /W 4 /H 4 /CS /RGB /BPC 8
ID
00000z0z00zzz00z0zzz0zzzEI aazazaazzzaazazzzazzz
EI

Steps to reproduce the problem:

  1. Open attached bi.pdf

What is the expected behavior? (add screenshot)
Screenshot 2019-09-06 at 19 06 30

This is how it looks in any other pdf viewer. All pixels are present and interpolation is off.

What went wrong? (add screenshot)
Screenshot 2019-09-06 at 18 54 20

Seems it stoped decoding image in middle where is byte sequence "EI " but in this context meant as color of pixel instead of "End of Image" keyword.

Another thing is that it uses image interpolation even that it should be disabled by default in pdf.

To enable interpolation it has to be:

BI /W 4 /H 4 /CS /RGB /BPC 8 /I true

Then it would look like this in correct pdf viewer:
Screenshot 2019-09-06 at 19 11 47

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