diff --git a/src/decoder/stream.rs b/src/decoder/stream.rs index e12ac4e..cf67d5d 100644 --- a/src/decoder/stream.rs +++ b/src/decoder/stream.rs @@ -260,9 +260,9 @@ impl Read for PackBitsReader { pub struct Group4Reader { decoder: fax34::decoder::Group4Decoder>>>, line_buf: io::Cursor>, - height: u16, + height: u32, width: u16, - y: u16, + y: u32, } #[cfg(feature = "fax")] @@ -273,7 +273,7 @@ impl Group4Reader { compressed_length: u64, ) -> crate::TiffResult { let width = u16::try_from(dimensions.0)?; - let height = u16::try_from(dimensions.1)?; + let height = dimensions.1; Ok(Self { decoder: fax34::decoder::Group4Decoder::new( diff --git a/tests/decode_images.rs b/tests/decode_images.rs index 5448686..74f9f9f 100644 --- a/tests/decode_images.rs +++ b/tests/decode_images.rs @@ -720,3 +720,29 @@ fn extra_bits_gray() { fn extra_bits_rgb() { test_image_sum_u8("extra_bits_rgb_8b.tiff", ColorType::RGB(8), 0); } + +#[test] +#[cfg(feature = "fax")] +fn test_decode_huge_g4() { + let path = PathBuf::from(TEST_IMAGE_DIR).join("big_g4.tif"); + let img_file = File::open(path).expect("failed to open large G4 test image"); + let mut decoder = tiff::decoder::Decoder::new(img_file).expect("failed to create decoder"); + + let (width, height) = decoder.dimensions().expect("failed to get dimensions"); + + assert!( + height > u16::MAX as u32, + "Test image height {} is not large enough to test u16 overflow", + height + ); + + let result = decoder + .read_image() + .expect("failed to decode huge G4 image"); + + if let tiff::decoder::DecodingResult::U8(data) = result { + assert_eq!(data.len(), (width as usize * height as usize)); + } else { + panic!("Unexpected decoding result type"); + } +} diff --git a/tests/images/big_g4.tif b/tests/images/big_g4.tif new file mode 100644 index 0000000..2b3e738 Binary files /dev/null and b/tests/images/big_g4.tif differ