Fix infinite loop in JBIG2 decoder with symbol dictionary context retention#20539
Fix infinite loop in JBIG2 decoder with symbol dictionary context retention#20539Gaurang-5 wants to merge 1 commit intomozilla:masterfrom
Conversation
…ention and add regression test Implements JBIG2 spec section 7.4.2.2 steps 3 and 7 for bitmap coding context retention and reuse. When bitmapCodingContextUsed is set, the decoder now reuses arithmetic coding contexts from the last referred-to symbol dictionary instead of creating new ones. When bitmapCodingContextRetained is set, contexts are saved for future reuse. Fixes mozilla#20461
|
/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/070ff3f62b453a4/output.txt |
From: Bot.io (Linux m4)SuccessFull output at http://54.241.84.105:8877/070ff3f62b453a4/output.txt Total script time: 0.99 mins Published |
|
/botio test |
From: Bot.io (Linux m4)ReceivedCommand cmd_test from @timvandermeij received. Current queue size: 0 Live output at: http://54.241.84.105:8877/cff5b2f9e2dff4f/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/caaf5fe16482bc1/output.txt |
From: Bot.io (Linux m4)FailedFull output at http://54.241.84.105:8877/cff5b2f9e2dff4f/output.txt Total script time: 41.14 mins
Image differences available at: http://54.241.84.105:8877/cff5b2f9e2dff4f/reftest-analyzer.html#web=eq.log |
From: Bot.io (Windows)FailedFull output at http://54.193.163.58:8877/caaf5fe16482bc1/output.txt Total script time: 79.46 mins
Image differences available at: http://54.193.163.58:8877/caaf5fe16482bc1/reftest-analyzer.html#web=eq.log |
| } | ||
|
|
||
| // Reuse the arithmetic coding contexts | ||
| decodingContext.contextCache = retainedContexts.contextCache; |
There was a problem hiding this comment.
If I open the PDF file from this commit with the preview build at http://54.241.84.105:8877/070ff3f62b453a4/web/viewer.html there is no infinite loop anymore, but I also don't see any image rendering, and the console shows this:
Warning: Unable to decode image "img_p0_1": "TypeError: setting getter-only property "contextCache"". pdf.worker.mjs:357:13
Warning: Dependent image isn't ready yet
That seems to relate to this line, so it looks like this may not actually work as expected?
Description
Fixes an infinite loop in the JBIG2 decoder when processing PDFs that use symbol dictionary context retention and reuse features.
Problem
The JBIG2 decoder was missing the implementation of bitmap coding context retention and reuse as specified in ISO/IEC 14492 section 7.4.2.2, steps 3 and 7. When a PDF used these features (indicated by the
bitmapCodingContextUsedandbitmapCodingContextRetainedflags), the decoder would enter an infinite loop because it was creating new arithmetic coding contexts instead of reusing existing ones.Solution
This PR implements:
Context retention: When
bitmapCodingContextRetainedis set, the decoder now stores the arithmetic coding contexts after decoding a symbol dictionary, indexed by segment number.Context reuse: When
bitmapCodingContextUsedis set, the decoder retrieves and reuses contexts from the last referred-to symbol dictionary segment. The implementation includes validation to ensure that the coding parameters (huffman, refinement, template, refinementTemplate) match between the original and reusing segments.Helper methods: Added
getRetainedBitmapContexts()andsetRetainedBitmapContexts()to manage the context storage.The fix properly assigns
decodingContext.contextCacheduring reuse instead of leaving it undefined, which eliminates the infinite loop.Testing
bitmap-symbol-context-reuse.pdfthat previously caused an infinite looptest_manifest.jsonwith test entry for issue 20461Fixes #20461