-
Notifications
You must be signed in to change notification settings - Fork 146
Splat adam7 interlacing #576
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
base: master
Are you sure you want to change the base?
Splat adam7 interlacing #576
Conversation
@anforowicz Please review this PR and share your suggestions on the TODOs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
I think filling the image pixels completely is the expected behavior, so it would be nice to make this easy/default, but I'm not sure how such thing could be integrated with the library API. Doing this in |
@kornelski and/or @fintelia - can you take another look please? |
info: &Adam7Info, | ||
bits_pp: usize, | ||
bit_pos: usize, | ||
frame_width_in_bits: usize, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm suspicious that this might overflow on 32-bit systems. The problem isn't so much that there's likely to be many valid images more than 500 million pixels wide, but rather that fuzzers are really good at figuring out how to populate header fields so that the code reaches the overflow before noticing that the rest of the file is corrupt.
(Looking now, I think the existing expand_adam7_bits code might have the same issue)
src/adam7.rs
Outdated
bytes_pp: usize, | ||
start_byte: usize, | ||
) { | ||
let height = (img.len() - start_byte + stride - 1) / stride; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can use the div_ceil
method
line_mul: usize, | ||
line_off: usize, | ||
samp_mul: usize, | ||
samp_off: usize, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rust convention is to mostly avoid abbreviations in variable names. So for instance, sample_offset
rather than samp_off
6 => ((w - 1.0) / 2.0, h / 2.0), | ||
7 => (w, (h - 1.0) / 2.0), | ||
_ => unreachable!(), | ||
let (line_mul, line_off, samp_mul, samp_off) = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this whole function can be simplified a bunch. If I'm not missing something, should be a matter of...
let pass = PASS_CONSTANTS[self.current_pass as usize - 1];
self.line_width = (self.width - pass.samp_off).div_ceil(pass.samp_mul);
self.lines = (self.width - pass.line_off).div_ceil(pass.line_mul);
self.line = 0;
(And making the constants u32
rather than usize
)
@fintelia I've made the necessary changes for the splat expand pass. However, updating the parameter types as discussed, like changing Would it make sense to create a separate issue to track the type changes and have further discussions around using |
I'm OK with deferring changes to other parts of the codebase, but I do want to make sure that this PR doesn't introduce new integer overflow bugs. At a minimum, we absolutely cannot do |
As a follow-up to this issue in Chromium, I created a corresponding PR in
image-png
.CC: @anforowicz