From d28ad274b380b6a4ec7a97fe214cf351d63124fd Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Mon, 23 Nov 2026 23:58:51 -0800 Subject: [PATCH] image-codecs: borrow the ICC profile and EXIF in the PNG header The PNG writer copied the caller's ICC profile, and the exported EXIF, into new buffers before writing the header. Each tagged save allocated a second profile-sized buffer that could abort the process when memory ran short. The header now borrows the profile, and borrows the EXIF whenever export_exif returns it unchanged. --- crates/image-codecs/src/codecs/png.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/image-codecs/src/codecs/png.rs b/crates/image-codecs/src/codecs/png.rs index d54d4149bf..68c1a860ab 100644 --- a/crates/image-codecs/src/codecs/png.rs +++ b/crates/image-codecs/src/codecs/png.rs @@ -1360,12 +1360,12 @@ fn start( if opts.embed_icc && let Some(icc) = icc { - info.icc_profile = Some(icc.clone().into()); + info.icc_profile = Some(std::borrow::Cow::Borrowed(icc.as_slice())); } if opts.embed_metadata { if let Some(exif) = &meta.exif { // The pixels are written as they are shown: never let a viewer rotate them again. - info.exif_metadata = Some(crate::resolution::export_exif(exif, meta.dpi).into_owned().into()); + info.exif_metadata = Some(crate::resolution::export_exif(exif, meta.dpi)); } if let Some((x, y)) = meta.dpi && x > 0.0