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

Fix crash on width or height of 1 #2644

Merged
merged 1 commit into from
Jan 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -856,8 +856,8 @@ impl<W: io::Write> UncompressedHeader for BitWriter<W, BigEndian> {
// when we add support for it.
let width = fi.width - 1;
let height = fi.height - 1;
let width_bits = 32 - (width as u32).leading_zeros();
let height_bits = 32 - (height as u32).leading_zeros();
let width_bits = log_in_base_2(width as u32) as u32 + 1;
let height_bits = log_in_base_2(height as u32) as u32 + 1;
assert!(width_bits <= 16);
assert!(height_bits <= 16);
self.write(4, width_bits - 1)?;
Expand All @@ -875,8 +875,8 @@ impl<W: io::Write> UncompressedHeader for BitWriter<W, BigEndian> {
if fi.frame_size_override_flag {
let width = fi.width - 1;
let height = fi.height - 1;
let width_bits = 32 - (width as u32).leading_zeros();
let height_bits = 32 - (height as u32).leading_zeros();
let width_bits = log_in_base_2(width as u32) as u32 + 1;
let height_bits = log_in_base_2(height as u32) as u32 + 1;
assert!(width_bits <= 16);
assert!(height_bits <= 16);
self.write(width_bits, width as u16)?;
Expand Down
7 changes: 6 additions & 1 deletion src/test_encode_decode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ mod small_dimension {

mod tiny_dimension {
test_dimensions! {
(1, 1),
(2, 2),
(4, 4),
(8, 8),
(16, 16),
(32, 32),
(64, 64),
Expand All @@ -297,6 +301,7 @@ fn dimension(w: usize, h: usize, decoder: &str) {
let quantizer = 100;
let limit = 1;
let speed = 10;
let still_picture = w < 16 || h < 16;

let mut dec = get_decoder::<u8>(decoder, w as usize, h as usize);
dec.encode_decode(
Expand All @@ -315,7 +320,7 @@ fn dimension(w: usize, h: usize, decoder: &str) {
0,
0,
0,
false,
still_picture,
);
}

Expand Down