Pdf.js: pdf file decode success but not show anything

Created on 11 Apr 2017  路  7Comments  路  Source: mozilla/pdf.js

Link to PDF file (or attach file here): PDF file

Configuration:

  • Web browser and its version: Chrome 57.0
  • Operating system and its version: macOS Sierra 10.12.3
  • PDF.js version: 1.7.416

Steps to reproduce the problem:

  1. open the example url https://mozilla.github.io/pdf.js/web/viewer.html
  2. upload this file, decode success but this viewer is all blank.

What went wrong? (add screenshot)
this file have many content, but in viewer, is no content to display.
error screenshot

3-pdf-broken 4-image-conversion 4-image-jbig2

Most helpful comment

The problem may be in function decodeRefinement() (jbig2.js) in the following lines:

          i0 = i + referenceTemplateY[k] + offsetY;
          j0 = j + referenceTemplateX[k] + offsetX;

As the JBIG2 standard says, offsetX and offsetY should be subtracted, not added. So the lines should be like this:

          i0 = i + referenceTemplateY[k] - offsetY;
          j0 = j + referenceTemplateX[k] - offsetX;

See page 21 in standard ITU T.88, in which the offsets are called GRREFERENCEDX and GRREFERENCEDY.

The JBIG2 images in the PDF use decodeRefinement() to refine symbol bitmaps. Because of this bug, wrong contextLabel bits are fed to the arithmetic decoder. The decoder gets "confused" and it no longer returns valid decoding results.

All 7 comments

The problem may be in function decodeRefinement() (jbig2.js) in the following lines:

          i0 = i + referenceTemplateY[k] + offsetY;
          j0 = j + referenceTemplateX[k] + offsetX;

As the JBIG2 standard says, offsetX and offsetY should be subtracted, not added. So the lines should be like this:

          i0 = i + referenceTemplateY[k] - offsetY;
          j0 = j + referenceTemplateX[k] - offsetX;

See page 21 in standard ITU T.88, in which the offsets are called GRREFERENCEDX and GRREFERENCEDY.

The JBIG2 images in the PDF use decodeRefinement() to refine symbol bitmaps. Because of this bug, wrong contextLabel bits are fed to the arithmetic decoder. The decoder gets "confused" and it no longer returns valid decoding results.

@janpe2 it works, thanks so much.

@janpe2 Could you open a pull request for that bugfix ?

I'm not exactly familiar with the pull request process in GitHub. Could somebody make a pull request on my behalf? Someone who is more experienced...

BTW, my fix may resolve also issues #7850 , #7308 and #7145. Maybe also #7401?

@janpe2 Very nice debugging, thank you!

It seems that this has been broken ever since JBIG2 support was first added, all the way back in PR #1837. Interestingly, in the test-case added in that PR all offsets are 0, which probably explains why this bug managed to creep into the code.

I'm not exactly familiar with the pull request process in GitHub. Could somebody make a pull request on my behalf? Someone who is more experienced...

The contribution work-flow is described in https://github.com/mozilla/pdf.js/wiki/Contributing, if you feel like trying it yourself.
If not, I suppose that I can help you with the creation of a patch[1]. However, since you should obviously be credited as the author (it's your patch after all), please tell me what name (and optionally what e-mail address) you'd want to appear in the patch!


[1] I just ran the PDF.js test-suite (locally) with your changes, and everything seemed to work just fine :-)

@Snuffleupagus I would be happy if you could create the patch, please. I think I don't have enough skills to follow the contribution work-flow. In the credits you can mention my name Jani Pehkonen.

Thank you very much. It worked. Actually, for me, the function decodeRefinement() is in pdf.worker.js

Was this page helpful?
0 / 5 - 0 ratings

Related issues

BrennanDuffey picture BrennanDuffey  路  3Comments

liuzhen2008 picture liuzhen2008  路  4Comments

sujit-baniya picture sujit-baniya  路  3Comments

jigskpatel picture jigskpatel  路  3Comments

PeterNerlich picture PeterNerlich  路  3Comments