Fix infinite loop in JBIG2 decoder with >4 referred-to segments#20440
Fix infinite loop in JBIG2 decoder with >4 referred-to segments#20440timvandermeij merged 1 commit intomozilla:masterfrom
Conversation
|
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. |
|
@timvandermeij The test file is located at:
Please let me know if you need any changes! |
|
/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. |
|
Done! I've squashed the commits into a single clean commit as requested. The PR is now ready to merge. Thanks! |
…dd regression test
|
/botio test |
From: Bot.io (Linux m4)ReceivedCommand cmd_test from @timvandermeij received. Current queue size: 1 Live output at: http://54.241.84.105:8877/c457a3e224d9051/output.txt |
From: Bot.io (Windows)ReceivedCommand cmd_test from @timvandermeij received. Current queue size: 1 Live output at: http://54.193.163.58:8877/86124cc6f5f9a3c/output.txt |
From: Bot.io (Linux m4)FailedFull output at http://54.241.84.105:8877/c457a3e224d9051/output.txt Total script time: 39.73 mins
Image differences available at: http://54.241.84.105:8877/c457a3e224d9051/reftest-analyzer.html#web=eq.log |
From: Bot.io (Windows)FailedFull output at http://54.193.163.58:8877/86124cc6f5f9a3c/output.txt Total script time: 75.17 mins
Image differences available at: http://54.193.163.58:8877/86124cc6f5f9a3c/reftest-analyzer.html#web=eq.log |
|
/botio-linux preview |
From: Bot.io (Linux m4)ReceivedCommand cmd_preview from @timvandermeij received. Current queue size: 0 Live output at: http://54.241.84.105:8877/969a152bef79088/output.txt |
From: Bot.io (Linux m4)SuccessFull output at http://54.241.84.105:8877/969a152bef79088/output.txt Total script time: 0.97 mins Published |
|
Thank you for your contribution! /botio makeref |
From: Bot.io (Linux m4)ReceivedCommand cmd_makeref from @timvandermeij received. Current queue size: 0 Live output at: http://54.241.84.105:8877/76a6d0fd585c888/output.txt |
From: Bot.io (Windows)ReceivedCommand cmd_makeref from @timvandermeij received. Current queue size: 0 Live output at: http://54.193.163.58:8877/07e85e9bcfc29f5/output.txt |
From: Bot.io (Linux m4)SuccessFull output at http://54.241.84.105:8877/76a6d0fd585c888/output.txt Total script time: 17.81 mins
|
From: Bot.io (Windows)SuccessFull output at http://54.193.163.58:8877/07e85e9bcfc29f5/output.txt Total script time: 30.25 mins
|
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