Repository navigation
[V4] Recover JPEG restart markers through the shared reader - #3258
Draft
JimBobSquarePants wants to merge 3 commits into
Draft
JimBobSquarePants wants to merge 3 commits into
JimBobSquarePants wants to merge 3 commits into
Conversation
…en decoding jpegs A TEM marker (FF 01) between header segments was read as a marker with a length field, so the next segment header was consumed as its length and decoding failed. TEM stands alone like RSTn, so skip it the same way. Some producers write extraneous bytes before restart markers. Those that form a TEM or reserved marker (FF 01 to FF BF) were taken as the end of the scan, which corrupted the rest of the image or made the marker parser fail. Skip them while looking for the marker that ends a restart interval and resync at the next marker, as libjpeg does.
4 tasks done
3 of 4 tasks
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prerequisites
Description
Backports #3225 to
release/4.1.x.JPEG header parsing now skips standalone TEM markers without reading the next marker as a segment length. At restart boundaries, the shared reader recovers from TEM and reserved marker codes only with
SegmentIntegrityHandling.IgnoreImageData.StrictandIgnoreAncillaryreject that damaged scan data. Both Huffman and arithmetic scans use the shared recovery. Arithmetic restart handling also checks the detected marker before resetting the reader.The cases extend the existing
JpegDecoderTests.cs. Stored inputs replace runtime encoding and byte modification. Native libjpeg-turbo produces identical pixels for the clean and recoverable files, with warnings for the damaged files. Tests require exact pixel equality and verify the integrity policies. Invalid required header lengths remain fatal under every policy.The arithmetic fixtures declare their conditioning tables explicitly. The separate existing failure for progressive arithmetic files that rely on standard AC conditioning defaults remains outside this fix.
Validation: Release JPEG and TIFF tests pass on .NET 8 and .NET 10: 1,449 passed, one existing debug-only skip, zero failed on each target. No public API, tolerances, reference images, or
BufferedReadStreamcode changed.Fixes #3237