From 4a59d98a706a8e813125cddc6eca4da22449c53c Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 20 Feb 2024 16:41:29 +1300 Subject: [PATCH] Workaround weird regression with &[u8] and zopfli --- src/deflate/zopfli_oxipng.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/deflate/zopfli_oxipng.rs b/src/deflate/zopfli_oxipng.rs index cb6e6eb4..b77e3164 100644 --- a/src/deflate/zopfli_oxipng.rs +++ b/src/deflate/zopfli_oxipng.rs @@ -8,7 +8,9 @@ pub fn deflate(data: &[u8], iterations: NonZeroU8) -> PngResult> { iteration_count: iterations.into(), ..Default::default() }; - match zopfli::compress(options, zopfli::Format::Zlib, data, &mut output) { + // Since Rust v1.74, passing &[u8] directly into zopfli causes a regression in compressed size + // for some files. Wrapping the slice in another Read implementer such as Box fixes it for now. + match zopfli::compress(options, zopfli::Format::Zlib, Box::new(data), &mut output) { Ok(_) => (), Err(_) => return Err(PngError::new("Failed to compress in zopfli")), };