diff --git a/1269c12.patch b/1269c12.patch new file mode 100644 index 0000000..799fe4b --- /dev/null +++ b/1269c12.patch @@ -0,0 +1,58 @@ +From 1269c1210c88a5adfcc8104b5d41e6706d06607b Mon Sep 17 00:00:00 2001 +From: Jonathan Behrens +Date: Sat, 13 Jan 2024 19:52:12 -0500 +Subject: [PATCH] Fix reference tests on big endian (#2099) + +--- + tests/reference_images.rs | 28 +++++++++++++++++++++++++--- + 1 file changed, 25 insertions(+), 3 deletions(-) + +diff --git a/tests/reference_images.rs b/tests/reference_images.rs +index d07423f23f..015d6a6e09 100644 +--- a/tests/reference_images.rs ++++ b/tests/reference_images.rs +@@ -1,4 +1,5 @@ + //! Compares the decoding results with reference renderings. ++use std::convert::TryInto; + use std::fs; + use std::io; + use std::path::PathBuf; +@@ -270,14 +271,35 @@ fn check_references() { + + let test_crc_actual = { + let mut hasher = Crc32::new(); +- hasher.update(test_img.as_bytes()); ++ match test_img { ++ DynamicImage::ImageLuma8(_) ++ | DynamicImage::ImageLumaA8(_) ++ | DynamicImage::ImageRgb8(_) ++ | DynamicImage::ImageRgba8(_) => hasher.update(test_img.as_bytes()), ++ DynamicImage::ImageLuma16(_) ++ | DynamicImage::ImageLumaA16(_) ++ | DynamicImage::ImageRgb16(_) ++ | DynamicImage::ImageRgba16(_) => { ++ for v in test_img.as_bytes().chunks(2) { ++ hasher.update(&u16::from_ne_bytes(v.try_into().unwrap()).to_le_bytes()); ++ } ++ } ++ DynamicImage::ImageRgb32F(_) | DynamicImage::ImageRgba32F(_) => { ++ for v in test_img.as_bytes().chunks(4) { ++ hasher.update(&f32::from_ne_bytes(v.try_into().unwrap()).to_le_bytes()); ++ } ++ } ++ _ => panic!("Unsupported image format"), ++ } + hasher.finalize() + }; + + if test_crc_actual != case.crc { + panic!( +- "The decoded image's hash does not match (expected = {:08x}, actual = {:08x}).", +- case.crc, test_crc_actual ++ "{}: The decoded image's hash does not match (expected = {:08x}, actual = {:08x}).", ++ img_path.display(), ++ case.crc, ++ test_crc_actual + ); + } + diff --git a/14d4577.patch b/14d4577.patch new file mode 100644 index 0000000..10590ee --- /dev/null +++ b/14d4577.patch @@ -0,0 +1,41 @@ +From 14d45771a9820dd14cb1533505098225624d7250 Mon Sep 17 00:00:00 2001 +From: Jonathan Behrens +Date: Sat, 13 Jan 2024 20:33:24 -0500 +Subject: [PATCH] Avoid overflow in gif::Decoder::buffer_size (#2103) + +--- + src/codecs/gif.rs | 11 ++++++++--- + 1 file changed, 8 insertions(+), 3 deletions(-) + +diff --git a/src/codecs/gif.rs b/src/codecs/gif.rs +index 6f3f87d09c..8b6f5ee26f 100644 +--- a/src/codecs/gif.rs ++++ b/src/codecs/gif.rs +@@ -37,6 +37,8 @@ use gif::{DisposalMethod, Frame}; + + use crate::animation::{self, Ratio}; + use crate::color::{ColorType, Rgba}; ++use crate::error::LimitError; ++use crate::error::LimitErrorKind; + use crate::error::{ + DecodingError, EncodingError, ImageError, ImageResult, ParameterError, ParameterErrorKind, + UnsupportedError, UnsupportedErrorKind, +@@ -177,12 +179,15 @@ impl<'a, R: 'a + Read> ImageDecoder<'a> for GifDecoder { + } else { + // If the frame does not match the logical screen, read into an extra buffer + // and 'insert' the frame from left/top to logical screen width/height. +- let buffer_size = self.reader.buffer_size(); ++ let buffer_size = (frame.width as usize) ++ .checked_mul(frame.height as usize) ++ .and_then(|s| s.checked_mul(4)) ++ .ok_or(ImageError::Limits(LimitError::from_kind( ++ LimitErrorKind::InsufficientMemory, ++ )))?; + + self.limits.reserve_usize(buffer_size)?; +- + let mut frame_buffer = vec![0; buffer_size]; +- + self.limits.free_usize(buffer_size); + + self.reader diff --git a/rust-image.spec b/rust-image.spec index 57d45c1..86a9120 100644 --- a/rust-image.spec +++ b/rust-image.spec @@ -16,6 +16,11 @@ Source: %{crates_source} # * drop unused, benchmark-only criterion dev-dependency # * disable little-endian-only openexr feature Patch: image-fix-metadata.diff +# * include upstream patches to fix issues on s390x and i686: +# https://github.com/image-rs/image/issues/2097 +# https://github.com/image-rs/image/issues/2098 +Patch: https://github.com/image-rs/image/commit/14d4577.patch +Patch: https://github.com/image-rs/image/commit/1269c12.patch BuildRequires: cargo-rpm-macros >= 24 @@ -260,7 +265,7 @@ use the "webp" feature of the "%{crate}" crate. %if %{with check} %check # * skip tests with missing test files (not included in published crates) -%cargo_test -- -- --exact --skip codecs::bmp::decoder::test::read_rect --skip codecs::png::tests::ensure_no_decoder_off_by_one --skip codecs::png::tests::underlying_error --skip codecs::qoi::tests::decode_test_image --skip dynimage::test::image_dimensions --skip dynimage::test::open_16bpc_png --skip imageops::sample::tests::resize_transparent_image --skip imageops::sample::tests::test_resize_same_size --skip imageops::sample::tests::test_sample_bilinear --skip imageops::sample::tests::test_sample_nearest --skip codecs::bmp::decoder::test::test_no_header +%cargo_test -- -- --exact --skip codecs::bmp::decoder::test::read_rect --skip codecs::png::tests::ensure_no_decoder_off_by_one --skip codecs::png::tests::underlying_error --skip codecs::qoi::tests::decode_test_image --skip dynimage::test::image_dimensions --skip dynimage::test::open_16bpc_png --skip imageops::sample::tests::resize_transparent_image --skip imageops::sample::tests::test_resize_same_size --skip imageops::sample::tests::test_sample_bilinear --skip imageops::sample::tests::test_sample_nearest --skip codecs::bmp::decoder::test::test_no_header --skip tiff %endif %changelog