Skip to content
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

jxl-frame: EC upsampling check #34

Merged
merged 2 commits into from
Jun 6, 2023

Conversation

EugeneVert
Copy link
Contributor

@EugeneVert EugeneVert commented Jun 4, 2023

No description provided.

@EugeneVert EugeneVert mentioned this pull request Jun 4, 2023
12 tasks
Comment on lines 235 to 236
let dim_shift = read_bits!(bitstream, U32(0, 3, 4, 1 + u(3)))?;
if (1usize << dim_shift) > 8 {
Copy link
Owner

@tirr-c tirr-c Jun 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed in jxl discord chat, there's something wrong in the check in libjxl; this makes decoded U32 value of 4 (10 in bitstream) instantly invalid. Instead we could defer the check to the frame header decoding.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, it seems to be an early check for dim_shift when ec_upsampling is not yet known.

@EugeneVert EugeneVert changed the title jxl-image: ExtraChannelInfo dim_shift check jxl-frame: EC upsampling check Jun 6, 2023
"EC upsampling < color upsampling, which is invalid").into()
);
}
if ec_up_cumulative > 8 {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I got it right, it's the dim_shift that makes the actual encoded block dimension smaller (to group_dim >> dim_shift), so only dim_shift should be checked here. The spec says that 1 << dim_shift does not exceed group_dim, so it makes sense; otherwise the actual dimension would be smaller than 1.

The required assertion is that (1 << dim_shift) <= group_dim, where group_dim = 1 << (7 + group_size_shift), so we need to check whether ec.dim_shift <= 7 + frame_header.group_size_shift holds.

@EugeneVert EugeneVert force-pushed the extra-channel-info-check branch 2 times, most recently from bc66859 to db8e682 Compare June 6, 2023 12:18
crates/jxl-frame/src/lib.rs Outdated Show resolved Hide resolved
@EugeneVert EugeneVert force-pushed the extra-channel-info-check branch from db8e682 to 9baeb00 Compare June 6, 2023 12:30
@EugeneVert
Copy link
Contributor Author

I should probably separate the dim_shift and ec_upsampling checks

Copy link
Owner

@tirr-c tirr-c left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few formatting nitpicks:

crates/jxl-frame/src/lib.rs Outdated Show resolved Hide resolved
crates/jxl-frame/src/lib.rs Outdated Show resolved Hide resolved
@tirr-c
Copy link
Owner

tirr-c commented Jun 6, 2023

I should probably separate the dim_shift and ec_upsampling checks

I feel like it's ok as is, but feel free to do so if you want to!

@EugeneVert EugeneVert force-pushed the extra-channel-info-check branch from 9baeb00 to 8a44c7b Compare June 6, 2023 12:42
Copy link
Owner

@tirr-c tirr-c left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, thanks!

@tirr-c tirr-c merged commit a54841c into tirr-c:main Jun 6, 2023
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.

2 participants