-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Fix infinite loop in JBIG2 decoder with >4 referred-to segments #20440
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
base: master
Are you sure you want to change the base?
Conversation
Fixes issue mozilla#20439 where pdf.js would hang on JBIG2 images with more than 4 referred-to segments. The bug had two parts: 1. Checking the entire referredFlags byte (=== 7) instead of the extracted referredToCount value (top 3 bits) 2. Incorrect byte count calculation for retention flags, missing the +1 for the segment's own retention bit According to the JBIG2 spec, retention flags need (referredToCount + 1) bits total: 1 for the segment itself plus 1 for each referred segment. The correct byte count is ceil((referredToCount + 1) / 8) which equals (referredToCount + 8) >> 3.
|
Please add a test case (see e.g. https://github.com/mozilla/pdf.js/pull/20270/files for how to do that) which serves as a regression test. After that we can trigger the tests here. |
|
Feel free to use the file attached to the issue :) |
|
@nico, it's super easy to add the test yourself:
commit and push. |
Add regression test for issue mozilla#20439 to ensure that JBIG2 images with more than 4 referred-to segments are handled correctly.
|
@timvandermeij The test file is located at:
Please let me know if you need any changes! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me like this, with the comment addressed, the commits squashed into one and passing tests. Thanks!
|
/botio test |
From: Bot.io (Windows)ReceivedCommand cmd_test from @calixteman received. Current queue size: 0 Live output at: http://54.193.163.58:8877/73e7f20e09be864/output.txt |
From: Bot.io (Linux m4)ReceivedCommand cmd_test from @calixteman received. Current queue size: 0 Live output at: http://54.241.84.105:8877/5a1410188c64b28/output.txt |
From: Bot.io (Linux m4)FailedFull output at http://54.241.84.105:8877/5a1410188c64b28/output.txt Total script time: 40.08 mins
Image differences available at: http://54.241.84.105:8877/5a1410188c64b28/reftest-analyzer.html#web=eq.log |
From: Bot.io (Windows)FailedFull output at http://54.193.163.58:8877/73e7f20e09be864/output.txt Total script time: 75.00 mins
Image differences available at: http://54.193.163.58:8877/73e7f20e09be864/reftest-analyzer.html#web=eq.log |
|
Could you squash the commits into one so we have a single commit for the change (see https://github.com/mozilla/pdf.js/wiki/Squashing-Commits if you're not familiar with how to do that)? This should be good to merge then. |
Fixes #20439
Summary
Fixes an infinite loop issue when decoding JBIG2 images with more than 4 referred-to segments.
Details
The bug had two parts:
Incorrect condition check: The code was checking the entire
referredFlagsbyte (referredFlags === 7) instead of checking the extractedreferredToCountvalue (the top 3 bits:referredToCount === 7)Incorrect byte count calculation: The calculation for retention flags bytes was
(referredToCount + 7) >> 3when it should be(referredToCount + 8) >> 3According to the JBIG2 specification, retention flags require
(referredToCount + 1)bits total: 1 bit for the segment itself plus 1 bit for each referred segment. The correct byte count isceil((referredToCount + 1) / 8)which equals(referredToCount + 8) >> 3.This issue was causing the parser to read incorrect positions, resulting in an infinite loop in the
readSegmentsfunction.Testing