Skip to content

Remove the unused /Decode handling from the JpegStream/JpegImage classes - #21809

Merged
Snuffleupagus merged 1 commit into
mozilla:masterfrom
Snuffleupagus:JpegImage-limit-decodeTransform
Aug 21, 2026
Merged

Remove the unused /Decode handling from the JpegStream/JpegImage classes#21809
Snuffleupagus merged 1 commit into
mozilla:masterfrom
Snuffleupagus:JpegImage-limit-decodeTransform

Conversation

@Snuffleupagus

@Snuffleupagus Snuffleupagus commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

According to the coverage data this code is now unused, see:

I've not attempted to find out exactly when it was made obsolete, however it most likely happened with the introduction of ImageDecoder.

Note that any /Decode entry is already parsed in the PDFImage constructor, see this code, and that the PDFImage.prototype.getImageBytes method is only ever invoked with the forceRGBA/forceRGB parameters set from this code respectively this code.
Note that both of those occurrences are placed within the following block:

pdf.js/src/core/image.js

Lines 834 to 839 in 9aea8e2

if (
this.image instanceof JpegStream &&
!this.smask &&
!this.mask &&
!this.needsDecode
) {

Hence, outside of the IMAGE_DECODERS build, there's no longer any reason for the JpegStream and JpegImage classes to implement their own /Decode handling.
Besides removing what's now dead code, it also improves consistency in the code-base given that none of the other image-decoders do this.

Finally, while slightly unrelated, move SMask/Mask checks in the PDFImage.prototype.createImageData method to occur earlier instead of unnecessarily repeating them later.


Slightly smaller diff with https://github.com/mozilla/pdf.js/pull/21809/changes?w=1

…classes

According to the coverage data this code is now unused, see:
 - https://app.codecov.io/gh/mozilla/pdf.js/commit/9aea8e2dfb142ad7c4e3a2595e8052e5dc8ce160/blob/src/core/jpeg_stream.js?dropdown=coverage#L74
 - https://app.codecov.io/gh/mozilla/pdf.js/commit/9aea8e2dfb142ad7c4e3a2595e8052e5dc8ce160/blob/src/core/jpeg_stream.js?dropdown=coverage#L149
 - https://app.codecov.io/gh/mozilla/pdf.js/commit/9aea8e2dfb142ad7c4e3a2595e8052e5dc8ce160/blob/src/core/jpg.js?dropdown=coverage#L1281

I've not attempted to find out exactly when it was made obsolete, however it most likely happened with the introduction of `ImageDecoder`.

Note that any /Decode entry is already parsed in the `PDFImage` constructor, see [this code](https://github.com/mozilla/pdf.js/blob/9aea8e2dfb142ad7c4e3a2595e8052e5dc8ce160/src/core/image.js#L267-L290), and that the `PDFImage.prototype.getImageBytes` method is only ever invoked with the `forceRGBA`/`forceRGB` parameters set from [this code](https://github.com/mozilla/pdf.js/blob/9aea8e2dfb142ad7c4e3a2595e8052e5dc8ce160/src/core/image.js#L868-L873) respectively [this code](https://github.com/mozilla/pdf.js/blob/9aea8e2dfb142ad7c4e3a2595e8052e5dc8ce160/src/core/image.js#L885-L890).
Note that both of those occurrences are placed within the following block: https://github.com/mozilla/pdf.js/blob/9aea8e2dfb142ad7c4e3a2595e8052e5dc8ce160/src/core/image.js#L834-L839

Hence, outside of the IMAGE_DECODERS build, there's no longer any reason for the `JpegStream` and `JpegImage` classes to implement their own /Decode handling.
Besides removing what's now dead code, it also improves consistency in the code-base given that none of the other image-decoders do this.

Finally, while slightly unrelated, move SMask/Mask checks in the `PDFImage.prototype.createImageData` method to occur earlier instead of unnecessarily repeating them later.
@codecov-commenter

codecov-commenter commented Aug 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 44.44444% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.19%. Comparing base (9aea8e2) to head (b1511e5).

Files with missing lines Patch % Lines
src/core/jpg.js 33.33% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #21809      +/-   ##
==========================================
- Coverage   90.19%   90.19%   -0.01%     
==========================================
  Files         264      264              
  Lines       67350    67339      -11     
==========================================
- Hits        60749    60734      -15     
- Misses       6601     6605       +4     
Flag Coverage Δ
browsertest 66.32% <44.44%> (+0.01%) ⬆️
fonttest 8.91% <0.00%> (+<0.01%) ⬆️
integrationtest 69.39% <44.44%> (-0.01%) ⬇️
unittest 58.35% <44.44%> (-0.01%) ⬇️
unittestcli 56.94% <44.44%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Snuffleupagus

Copy link
Copy Markdown
Collaborator Author

/botio browsertest

@moz-tools-bot

Copy link
Copy Markdown
Collaborator

From: Bot.io (Linux m4)


Received

Command cmd_browsertest from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.241.84.105:8877/d2f75828016aa6c/output.txt

@moz-tools-bot

Copy link
Copy Markdown
Collaborator

From: Bot.io (Windows)


Received

Command cmd_browsertest from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.193.163.58:8877/37edbe470854a82/output.txt

@moz-tools-bot

Copy link
Copy Markdown
Collaborator

From: Bot.io (Linux m4)


Success

Full output at http://54.241.84.105:8877/d2f75828016aa6c/output.txt

Total script time: 18.10 mins

  • Regression tests: Passed

@moz-tools-bot

Copy link
Copy Markdown
Collaborator

From: Bot.io (Windows)


Success

Full output at http://54.193.163.58:8877/37edbe470854a82/output.txt

Total script time: 23.13 mins

  • Regression tests: Passed

Comment thread src/core/jpg.js

@calixteman calixteman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. Thank you.

@Snuffleupagus
Snuffleupagus merged commit 0f26334 into mozilla:master Aug 21, 2026
21 checks passed
@Snuffleupagus
Snuffleupagus deleted the JpegImage-limit-decodeTransform branch August 21, 2026 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants