Skip to content

Fix a few edge cases when converting RGB images in convertRGBToRGBA and ImageResizer - #22046

Merged
timvandermeij merged 1 commit into
mozilla:masterfrom
calixteman:rgb-to-rgba-alignment
Oct 3, 2026
Merged

timvandermeij merged 1 commit into
mozilla:masterfrom
calixteman:rgb-to-rgba-alignment

Conversation

@calixteman

Copy link
Copy Markdown
Contributor
  • convertRGBToRGBA ignored the byteOffset of the source, which isn't zero when e.g. the data of an uncompressed image is read directly from the file, and it threw when the source wasn't 4-byte aligned. In that case all the pixels are now converted one by one. It also used len >> 2, which overflows for sources larger than 2 GiB.
  • In ImageResizer.#rescaleImageData, when the image had to be converted in several chunks:
    • if the chunk height divided the image height, the last chunk was converted with the full image height;
    • the rows were sampled relatively to each chunk, hence a chunk height which isn't a multiple of 2 ** K shifted the sub-sampling grid and left the last rows of the result empty. They're now sampled on the image grid;
    • the chunk height is rounded to a multiple of 4 when possible, in order to keep the RGB data aligned;
    • if not even a single row fitted in the buffer, the loop never ended.

@codecov-commenter

codecov-commenter commented Oct 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.27%. Comparing base (e9d1c85) to head (7594737).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #22046      +/-   ##
==========================================
- Coverage   90.37%   90.27%   -0.10%     
==========================================
  Files         269      269              
  Lines       67230    67235       +5     
==========================================
- Hits        60758    60699      -59     
- Misses       6472     6536      +64     
Flag Coverage Δ
browsertest 66.16% <73.33%> (+0.02%) ⬆️
fonttest 8.95% <0.00%> (-0.01%) ⬇️
integrationtest 69.23% <20.00%> (-0.15%) ⬇️
unittest 59.75% <93.33%> (+0.06%) ⬆️
unittestcli 58.27% <93.33%> (+0.07%) ⬆️

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.

Comment thread test/unit/image_resizer_spec.js Resolved

@timvandermeij timvandermeij left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good to me, with the comment above addressed. Thanks!

… and `ImageResizer`

 - `convertRGBToRGBA` ignored the `byteOffset` of the source, which isn't zero
   when e.g. the data of an uncompressed image is read directly from the file,
   and it threw when the source wasn't 4-byte aligned. In that case all the
   pixels are now converted one by one.
   It also used `len >> 2`, which overflows for sources larger than 2 GiB.
 - In `ImageResizer.#rescaleImageData`, when the image had to be converted in
   several chunks:
   - if the chunk height divided the image height, the last chunk was converted
     with the full image height;
   - the rows were sampled relatively to each chunk, hence a chunk height which
     isn't a multiple of `2 ** K` shifted the sub-sampling grid and left the
     last rows of the result empty. They're now sampled on the image grid;
   - the chunk height is rounded to a multiple of 4 when possible, in order to
     keep the RGB data aligned;
   - if not even a single row fitted in the buffer, the loop never ended.
@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Reference tests

Results for 7594737 (run, references from mozilla/pdf.js.refs@669ca76240).

Platform Status Tests Total runtime Errors Different FBF No reference Report
Linux ✅ 1381 10m 18s 0 0 0 0
Windows ✅ 1381 14m 15s 0 0 0 0

The report is kept for 30 days and replaced by the next run.

sync-pdfs-for-pdf-js Bot pushed a commit to mozilla/pdf.js.refs that referenced this pull request Oct 3, 2026
@timvandermeij
timvandermeij merged commit 7445074 into mozilla:master Oct 3, 2026
22 checks passed

This branch was previously deployed

1 inactive deployment
sync_pdfs — 7594737f Deployed Oct 3, 2026 by calixteman via request #250
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.

4 participants