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

Fix TypeError that occurs in colorspace.js on accidentally passing an 'Array' instead of 'TypedArray' #8666

Merged
merged 1 commit into from
Jul 25, 2017

Conversation

apoorv-mishra
Copy link
Contributor

Hi,
(Assumption: The base color space is set to be DeviceRGB)
If an Array(not as TypedArray or String) is passed in IndexedCS constructor(https://github.com/mozilla/pdf.js/blob/master/src/core/colorspace.js#L509) as lookup, TypeError occurs on calling fillRgb(...)(on IndexedCS object), passing lookup as comps(https://github.com/mozilla/pdf.js/blob/master/src/core/colorspace.js#L116-L118). The error occurs because of src.subarray(...) in https://github.com/mozilla/pdf.js/blob/master/src/core/colorspace.js#L635 since src is expected to be a TypedArray. I made a small change to fix this.

@Snuffleupagus
Copy link
Collaborator

/botio-linux preview

@Snuffleupagus
Copy link
Collaborator

Snuffleupagus commented Jul 19, 2017

Thanks for the patch, but I've got a couple of questions/suggestions below.

Did you successfully run the reference tests locally, as explained in https://github.com/mozilla/pdf.js/wiki/Contributing, with this patch?
Looking at the IRC logs, in particular http://logs.glob.uno/?c=mozilla%23pdfjs&s=18+Jul+2017&e=18+Jul+2017#c64549, it mentions TAMReview.pdf as an example of Indexed ColorSpace usage. It appears that this patch unfortunately breaks at least that file, and thus quite possibly others as well.

From looking at the history of the code, see PR #3334, it appears that the only reason for supporting Array at all was for IE9 compatibility. Note that the lookup parameter, as coming from a PDF file, should never actually be a regular Array.
Wouldn't a better solution be to change colorspace.js#L528-L529 to e.g. the following instead?

} else if (lookup instanceof Uint8Array) {
  this.lookup = lookup;
} else if (lookup instanceof Array) {
  this.lookup = new Uint8Array(lookup);

Also, please update the commit message (and PR title) to something a little more descriptive, since it's really impossible to tell what the patch does based on TypeError fix in colorspace.js without also reading the PR description. (In this case, even looking at the code itself doesn't really explain the reason for the change.)

@apoorv-mishra
Copy link
Contributor Author

Hi @Snuffleupagus , there is one more issue with making it as Uint8Array. Have a look at http://logs.glob.uno/?c=mozilla%23pdfjs&s=18+Jul+2017&e=18+Jul+2017#c64496.

@apoorv-mishra apoorv-mishra changed the title TypeError fix in colorspace.js Fix TypeError that occurs on calling base.getRgbBuffer(...) with 'lookup' as an 'Array' Jul 19, 2017
@apoorv-mishra apoorv-mishra changed the title Fix TypeError that occurs on calling base.getRgbBuffer(...) with 'lookup' as an 'Array' Fix TypeError in colorspace.js that occurs on accidentally passing an 'Array' instead of 'TypedArray' Jul 19, 2017
Copy link
Contributor

@yurydelendik yurydelendik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you need to change getRgbItem -> getRgbBuffer call in the IndexedCS_getRgbItem above.

@apoorv-mishra apoorv-mishra changed the title Fix TypeError in colorspace.js that occurs on accidentally passing an 'Array' instead of 'TypedArray' Fix TypeError that occurs in colorspace.js on accidentally passing an 'Array' instead of 'TypedArray' Jul 19, 2017
this.lookup = lookup;
} else if (lookup instanceof Array) {
this.lookup = new Uint8Array(lookup);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you revert the changes above? For IE9, it will not matter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

Copy link
Contributor

@yurydelendik yurydelendik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good (with just getRgbBuffer change)

@yurydelendik
Copy link
Contributor

/botio test

… 'Array' instead of 'TypedArray'

Fix TypeError that occurs in colorspace.js on accidentally passing an 'Array' instead of 'TypedArray'

Changed getRgbItem(...) to getRgbBuffer(...) since this.lookup has values in range[0, 255] whereas getRgbItem(...) expects those to be in range [0, 1]

Revert changes for IE9 compatibility
@mozilla mozilla deleted a comment from pdfjsbot Jul 24, 2017
@mozilla mozilla deleted a comment from pdfjsbot Jul 24, 2017
@mozilla mozilla deleted a comment from pdfjsbot Jul 24, 2017
@mozilla mozilla deleted a comment from pdfjsbot Jul 24, 2017
@mozilla mozilla deleted a comment from pdfjsbot Jul 24, 2017
@mozilla mozilla deleted a comment from pdfjsbot Jul 24, 2017
@timvandermeij
Copy link
Contributor

/botio-linux preview

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_preview from @timvandermeij received. Current queue size: 0

Live output at: http://54.67.70.0:8877/8b8ec0b4975c7dc/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/8b8ec0b4975c7dc/output.txt

Total script time: 2.38 mins

Published

@timvandermeij
Copy link
Contributor

/botio test

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

Command cmd_test from @timvandermeij received. Current queue size: 2

Live output at: http://54.215.176.217:8877/cef1bb0b5ee49e7/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

Command cmd_test from @timvandermeij received. Current queue size: 0

Live output at: http://54.67.70.0:8877/f003bbfb52e8025/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/f003bbfb52e8025/output.txt

Total script time: 16.58 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: Passed

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://54.215.176.217:8877/cef1bb0b5ee49e7/output.txt

Total script time: 29.34 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: Passed

@timvandermeij
Copy link
Contributor

Merging with r=yurydelendik. Thank you for the patch!

@timvandermeij timvandermeij merged commit 44a5cec into mozilla:master Jul 25, 2017
apoorv-mishra added a commit to apoorv-mishra/pdf.js that referenced this pull request Jul 26, 2017
Added unit-tests for DeviceGray, DeviceRGB and DeviceCMYK

Added unit-tests for CalGray

Added unit-tests for CalRGB

Removed redundant code

Added unit-tests for LabCS

Added unit-tests for IndexedCS

Update comment

Change lookup to Uint8Array as mentioned in pdf specs(these tests will pass after PR mozilla#8666 is merged).

Added unit-tests for AlternateCS
apoorv-mishra added a commit to apoorv-mishra/pdf.js that referenced this pull request Jul 28, 2017
Added unit-tests for DeviceGray, DeviceRGB and DeviceCMYK

Added unit-tests for CalGray

Added unit-tests for CalRGB

Removed redundant code

Added unit-tests for LabCS

Added unit-tests for IndexedCS

Update comment

Change lookup to Uint8Array as mentioned in pdf specs(these tests will pass after PR mozilla#8666 is merged).

Added unit-tests for AlternateCS

Resolved code-style issues
apoorv-mishra added a commit to apoorv-mishra/pdf.js that referenced this pull request Jul 28, 2017
Added unit-tests for DeviceGray, DeviceRGB and DeviceCMYK

Added unit-tests for CalGray

Added unit-tests for CalRGB

Removed redundant code

Added unit-tests for LabCS

Added unit-tests for IndexedCS

Update comment

Change lookup to Uint8Array as mentioned in pdf specs(these tests will pass after PR mozilla#8666 is merged).

Added unit-tests for AlternateCS

Resolved code-style issues

Fixed code-style issues
apoorv-mishra added a commit to apoorv-mishra/pdf.js that referenced this pull request Jul 28, 2017
Added unit-tests for DeviceGray, DeviceRGB and DeviceCMYK

Added unit-tests for CalGray

Added unit-tests for CalRGB

Removed redundant code

Added unit-tests for LabCS

Added unit-tests for IndexedCS

Update comment

Change lookup to Uint8Array as mentioned in pdf specs(these tests will pass after PR mozilla#8666 is merged).

Added unit-tests for AlternateCS

Resolved code-style issues

Fixed code-style issues

Addressed issues pointed out in mozilla#8611 (review)
@apoorv-mishra apoorv-mishra deleted the fix-colorspace branch August 1, 2017 15:46
movsb pushed a commit to movsb/pdf.js that referenced this pull request Jul 14, 2018
Fix TypeError that occurs in colorspace.js on accidentally passing an 'Array' instead of 'TypedArray'
movsb pushed a commit to movsb/pdf.js that referenced this pull request Jul 14, 2018
Added unit-tests for DeviceGray, DeviceRGB and DeviceCMYK

Added unit-tests for CalGray

Added unit-tests for CalRGB

Removed redundant code

Added unit-tests for LabCS

Added unit-tests for IndexedCS

Update comment

Change lookup to Uint8Array as mentioned in pdf specs(these tests will pass after PR mozilla#8666 is merged).

Added unit-tests for AlternateCS

Resolved code-style issues

Fixed code-style issues

Addressed issues pointed out in mozilla#8611 (review)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants