Skip to content

LibGfx/JBIG2: Validate more things#26191

Merged
nico merged 8 commits intoSerenityOS:masterfrom
nico:jbig2-stuff
Sep 6, 2025
Merged

LibGfx/JBIG2: Validate more things#26191
nico merged 8 commits intoSerenityOS:masterfrom
nico:jbig2-stuff

Conversation

@nico
Copy link
Contributor

@nico nico commented Sep 6, 2025

…and a few minor cleanups.

For writing JBIG2Writer, it's useful if the loader is pretty strict, to catch mistakes. (But not too strict to break real-world files, of course. If this does break any files in practice, we need to weaken it. I'm not aware of any files that this fires on though.)

nico added 8 commits September 5, 2025 21:58
Check that all referred-to segments exist, even for segments that aren't
needed for decoding an image. This is a bit stricter than before, but it
seems to be fine in practice, and it's simpler.

It allows us to have each segment store pointers to all segments they
refer to.
Some files in the power jbig2 test set incorrectly do associate a
page with EndOfFile, so don't check for that part for now.
@github-actions github-actions bot added the 👀 pr-needs-review PR needs review from a maintainer or community member label Sep 6, 2025
@nico nico merged commit e6d63b8 into SerenityOS:master Sep 6, 2025
12 checks passed
@nico nico deleted the jbig2-stuff branch September 6, 2025 12:44
@github-actions github-actions bot removed the 👀 pr-needs-review PR needs review from a maintainer or community member label Sep 6, 2025
nico added a commit to nico/serenity that referenced this pull request Sep 9, 2025
The extra validation in SerenityOS#26191 was added at the end of
decode_segment_headers(). But in decode_embedded(), that can be called
several times, once for each data chunk.

We want to decode segment headers from all chunks first before we
do validation, so that segments in later chunks can refer to segments
in earlier chunks.

Add a new complete_decoding_all_segment_headers() to house the
validation code, and call it after all segment chunks have been
decoded.

Unbreaks rendering 0000372.pdf page 11 and 0000857.pdf pages 1-4.
nico added a commit that referenced this pull request Sep 10, 2025
The extra validation in #26191 was added at the end of
decode_segment_headers(). But in decode_embedded(), that can be called
several times, once for each data chunk.

We want to decode segment headers from all chunks first before we
do validation, so that segments in later chunks can refer to segments
in earlier chunks.

Add a new complete_decoding_all_segment_headers() to house the
validation code, and call it after all segment chunks have been
decoded.

Unbreaks rendering 0000372.pdf page 11 and 0000857.pdf pages 1-4.
nico added a commit to nico/serenity that referenced this pull request Dec 27, 2025
jbig2enc, which is used by Google Books, sometimes writes files that
are technically invalid. Allow that in permissive mode.

To be able to check the referred-to segment's types, switch the loop
from iterating over header.referred_to_segment_numbers to iterating
over referred_to_segments directly (possible after the third commit
of SerenityOS#26191, 72cd151).

Fixes SerenityOS#26405.
nico added a commit that referenced this pull request Dec 27, 2025
jbig2enc, which is used by Google Books, sometimes writes files that
are technically invalid. Allow that in permissive mode.

To be able to check the referred-to segment's types, switch the loop
from iterating over header.referred_to_segment_numbers to iterating
over referred_to_segments directly (possible after the third commit
of #26191, 72cd151).

Fixes #26405.
Hendiadyoin1 pushed a commit to Hendiadyoin1/serenity that referenced this pull request Jan 2, 2026
jbig2enc, which is used by Google Books, sometimes writes files that
are technically invalid. Allow that in permissive mode.

To be able to check the referred-to segment's types, switch the loop
from iterating over header.referred_to_segment_numbers to iterating
over referred_to_segments directly (possible after the third commit
of SerenityOS#26191, 72cd151).

Fixes SerenityOS#26405.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant