Skip to content
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

Unable to decode image: InvalidStateError #17190

Closed
srshupe opened this issue Oct 26, 2023 · 7 comments · Fixed by #19095
Closed

Unable to decode image: InvalidStateError #17190

srshupe opened this issue Oct 26, 2023 · 7 comments · Fixed by #19095
Assignees

Comments

@srshupe
Copy link

srshupe commented Oct 26, 2023

Attach (recommended) or Link to PDF file here:
org_AVA89V01U0$ (Black).pdf

Configuration:

  • Web browser and its version: Chrome Version 118.0.5993.89 (Official Build) (64-bit)
  • Firefox Version 119.0 (64-bit)
  • Edge Version 118.0.2088.69 (Official build) (64-bit)
  • Operating system and its version: Windows 11 Enterprise Version 10.0.22621 Build 22621
  • PDF.js version: 4.0.132 [3478112] (test viewer)
  • Is a browser extension: No

Steps to reproduce the problem:

  1. Open the file in Acrobat. Main area is blacked out but you can see the edges of a CAD drawing along the borders that includes various characters.
  2. Open the file in PDF.js. Only the black rectangle in the center and the blue box in the upper right corner are rendered.

What is the expected behavior? (add screenshot)
This is the upper left corner at 200% zoom in Acrobat:
image

What went wrong? (add screenshot)
The console on Chrome:
PDF a8c52134c310cca513061a5a2ce6ca91 [1.3 - / -] (PDF.js: 4.0.132 [3478112])
util.js:367 Warning: Unable to decode image "img_p0_1": "InvalidStateError: The source image could not be decoded.".
util.js:367 Warning: Dependent image isn't ready yet

The console on Firefox:
PDF a8c52134c310cca513061a5a2ce6ca91 [1.3 - / -] (PDF.js: 4.0.132 [3478112]) app.js:1561:12
Warning: Unable to decode image "img_p0_1": "InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable". pdf.worker.mjs:339:13
Warning: Dependent image isn't ready yet 3 util.js:367:12

The console on Edge:
PDF a8c52134c310cca513061a5a2ce6ca91 [1.3 - / -] (PDF.js: 4.0.132 [3478112])
util.js:367 Warning: Unable to decode image "img_p0_1": "InvalidStateError: The source image could not be decoded.".
2util.js:367 Warning: Dependent image isn't ready yet
util.js:367 Warning: Dependent image isn't ready yet

This is the upper left corner at 200% zoom in Chrome:
image

Link to a viewer (if hosted on a site other than mozilla.github.io/pdf.js or as Firefox/Chrome extension):
https://mozilla.github.io/pdf.js/web/viewer.html

@Snuffleupagus
Copy link
Collaborator

Most likely the huge image dimensions are the problem, given the following excerpt (taken from http://brendandahl.github.io/pdf.js.utils/browser/):

Resources (dict)
    ProcSet (array) [id: 5, gen: 0]
    XObject (dict)
        Im0 (stream) [id: 6, gen: 0]
            BitsPerComponent = 1
            ColorSpace = /DeviceGray [id: 7, gen: 0]
            DecodeParms (dict)
            Filter = /CCITTFaxDecode
            Height = 19866
            Length = 1110922
            Name = /Im0
            Subtype = /Image
            Type = /XObject
            Width = 28087
            <view contents> download
        wspe_X1 (stream) [id: 11, gen: 0]
            BitsPerComponent = 1
            ColorSpace = /DeviceGray
            Decode (array)
            Filter = /JBIG2Decode
            Height = 19866
            Length = 76004
            Subtype = /Image
            Type = /XObject
            Width = 28087
        wspe_X2 (stream) [id: 10, gen: 0]
        wspe_X3 (stream) [id: 13, gen: 0]
        wspe_X4 (stream) [id: 17, gen: 0]

@srshupe
Copy link
Author

srshupe commented Nov 16, 2023

Most likely the huge image dimensions are the problem, given the following excerpt (taken from http://brendandahl.github.io/pdf.js.utils/browser/):

So what (roughly) is the limiting factor that keeps the large image from being downloaded and processed? It looks like the promise tasked with fetching the image just quits at some point.

@poerlang

This comment was marked as duplicate.

@usagibear
Copy link

usagibear commented Feb 12, 2024

I also get the same error but only for PDFs that are very large (130+ x 50+ in) and may or may not contain multiple page sizes (each page has different dimensions). My PDFs are the default outputs of using the utility TIFF2PDF.

What should we do with files that are too large? Is there a setting we can configure in PDF.js? Thanks!

Specifically, I'm using PDF.js in https://github.com/wojtekmaj/react-pdf v7.7.0.

@srshupe
Copy link
Author

srshupe commented Feb 13, 2024

I also get the same error but only for PDFs that are very large (130+ x 50+ in) and may or may not contain multiple page sizes (each page has different dimensions). My PDFs are the default outputs of using the utility TIFF2PDF.

What should we do with files that are too large? Is there a setting we can configure in PDF.js? Thanks!

Specifically, I'm using PDF.js in https://github.com/wojtekmaj/react-pdf v7.7.0.

Yes, this is our issue as well. Some further investigation has shown that both the image and the PDF are not very large in terms of memory, only in physical dimensions. Is it a matter of allocating memory for the bitmap within PDF.js?

@calixteman
Copy link
Contributor

As mentioned in #17190 (comment) the image size is the issue.
After having been decoded it'll require 19866 x 28087 x 4 (RGBA) bytes which is greater than 2**31 - 1 and in Firefox for example the max size of an image is gfx.max-alloc-size (see about:config or https://searchfox.org/mozilla-central/source/modules/libpref/init/StaticPrefList.yaml#6174).
We could probably split the image into several ones, resize them and draw the smaller versions on the same resized canvas.

@srshupe
Copy link
Author

srshupe commented Nov 23, 2024

Has there been any progress on this issue?

As mentioned in #17190 (comment) the image size is the issue. After having been decoded it'll require 19866 x 28087 x 4 (RGBA) bytes which is greater than 2**31 - 1 and in Firefox for example the max size of an image is gfx.max-alloc-size (see about:config or https://searchfox.org/mozilla-central/source/modules/libpref/init/StaticPrefList.yaml#6174). We could probably split the image into several ones, resize them and draw the smaller versions on the same resized canvas.

Chrome's built-in PDF viewer is able to handle the sample document. Do you suppose they are doing something like the above?

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

Successfully merging a pull request may close this issue.

5 participants