From 26ba9bd30e2389795814b72471acc750a24b8adc 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 651632a9..1412b838 100644 --- a/src/deflate/zopfli_oxipng.rs +++ b/src/deflate/zopfli_oxipng.rs @@ -7,7 +7,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")), };