From ce5242a04d9719f265ef23d1b36cfa115d583eb0 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 16:26:57 +0000 Subject: [PATCH 1/9] Use shared JPEG marker inspection --- Cargo.lock | 40 +++++++--- Cargo.toml | 2 +- crates/codecs/Cargo.toml | 1 + crates/codecs/src/jpeg.rs | 162 +------------------------------------- 4 files changed, 36 insertions(+), 169 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 04c07b04f1..737de69d5b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1269,7 +1269,7 @@ version = "0.1.0" source = "git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18#f0f4758c01581d79577b9bf5046c06f4e77b1f18" dependencies = [ "craft-jpeg", - "craft-metadata", + "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18)", "exr", "flate2", "half", @@ -1304,6 +1304,18 @@ dependencies = [ "thiserror 2.0.21", ] +[[package]] +name = "craft-metadata" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=091baf624fcaa67ad740c2ea9d6df3216b4bddc7#091baf624fcaa67ad740c2ea9d6df3216b4bddc7" +dependencies = [ + "brotli-decompressor 6.0.1", + "chrono", + "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=091baf624fcaa67ad740c2ea9d6df3216b4bddc7)", + "quick-xml 0.41.0", + "serde", +] + [[package]] name = "craft-metadata" version = "0.1.0" @@ -1311,7 +1323,7 @@ source = "git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9b dependencies = [ "brotli-decompressor 6.0.1", "chrono", - "craft-tiff", + "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18)", "quick-xml 0.41.0", "serde", ] @@ -1334,8 +1346,8 @@ source = "git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9b dependencies = [ "chrono", "craft-crw", - "craft-metadata", - "craft-tiff", + "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18)", + "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18)", "jxl-oxide", "miniz_oxide 0.9.1", "rayon", @@ -1345,6 +1357,15 @@ dependencies = [ "zune-jpeg", ] +[[package]] +name = "craft-tiff" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=091baf624fcaa67ad740c2ea9d6df3216b4bddc7#091baf624fcaa67ad740c2ea9d6df3216b4bddc7" +dependencies = [ + "serde", + "thiserror 2.0.21", +] + [[package]] name = "craft-tiff" version = "0.1.0" @@ -3833,8 +3854,9 @@ dependencies = [ "craft-heif", "craft-image-codecs", "craft-jxl", + "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=091baf624fcaa67ad740c2ea9d6df3216b4bddc7)", "craft-psd", - "craft-tiff", + "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18)", "dhat", "jxl-oxide", "lightcraft-color", @@ -3911,7 +3933,7 @@ dependencies = [ "chrono", "craft-docpath", "craft-heif", - "craft-tiff", + "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18)", "crc32fast", "fs4", "harfrust 0.13.3", @@ -4068,9 +4090,9 @@ version = "0.21.1" dependencies = [ "chrono", "craft-heif", - "craft-metadata", + "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=091baf624fcaa67ad740c2ea9d6df3216b4bddc7)", "craft-psd", - "craft-tiff", + "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18)", "lightcraft-geom", "proptest", "serde", @@ -4125,7 +4147,7 @@ dependencies = [ "chrono", "craft-image-codecs", "craft-raw", - "craft-tiff", + "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18)", "dhat", "lightcraft-color", "lightcraft-geom", diff --git a/Cargo.toml b/Cargo.toml index 2346d9cd48..02ec034da6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ craft-cms = { git = "https://github.com/storytold/craft-libs", rev = "f0f4758c01 craft-gif = { git = "https://github.com/storytold/craft-libs", rev = "b77af389f30bb10de10d8436ca9b39fe94e3bb67", features = ["frames"] } craft-jxl = { git = "https://github.com/storytold/craft-libs", rev = "b77af389f30bb10de10d8436ca9b39fe94e3bb67", default-features = false, features = ["decode", "encode"] } # Photo metadata: EXIF, IPTC-IIM, XMP packets and GPX track logs (craft-libs#949) -craft-metadata = { git = "https://github.com/storytold/craft-libs", rev = "f0f4758c01581d79577b9bf5046c06f4e77b1f18" } +craft-metadata = { git = "https://github.com/storytold/craft-libs", rev = "091baf624fcaa67ad740c2ea9d6df3216b4bddc7" } craft-image-codecs = { git = "https://github.com/storytold/craft-libs", rev = "f0f4758c01581d79577b9bf5046c06f4e77b1f18" } craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "f0f4758c01581d79577b9bf5046c06f4e77b1f18" } # craft-update: app-specific pretend versions apply to startup and manual checks. diff --git a/crates/codecs/Cargo.toml b/crates/codecs/Cargo.toml index f74c413634..b61e61ca90 100644 --- a/crates/codecs/Cargo.toml +++ b/crates/codecs/Cargo.toml @@ -15,6 +15,7 @@ lightcraft-raster = { workspace = true } craft-gainmap = { workspace = true } craft-cms = { workspace = true } craft-image-codecs = { workspace = true } +craft-metadata = { workspace = true } craft-tiff = { workspace = true } craft-gif = { workspace = true } craft-psd = { workspace = true } diff --git a/crates/codecs/src/jpeg.rs b/crates/codecs/src/jpeg.rs index ccb37548c9..a988da567c 100644 --- a/crates/codecs/src/jpeg.rs +++ b/crates/codecs/src/jpeg.rs @@ -6,166 +6,10 @@ use crate::{DecodeOptions, Decoded, Error, Format, Result, Thumbnail, ThumbnailS const F: Format = Format::Jpeg; -/// What we learn from walking the marker segments before the first scan. -#[derive(Default, Debug)] -pub(crate) struct Markers { - pub width: u32, - pub height: u32, - pub components: u8, - pub precision: u8, - /// SOFn marker byte (0xC0 baseline, 0xC1 extended, 0xC2 progressive, …). - pub sof: u8, - /// Number of components in the first scan (< `components` for non-interleaved sequential files). - pub first_scan_components: u8, - /// Number of APP1 segments: capped before the allocating decoders walk them again. - pub app1: u32, - pub exif: Option>, - /// Offset of the EXIF TIFF header within the file. - pub exif_offset: usize, - pub xmp: Option, - pub icc: Option>, - /// An ICC_PROFILE APP2 segment was present but its sequence was invalid. - pub icc_invalid: bool, - pub adobe_transform: Option, - /// Offset of the MPF TIFF header within the file and its bytes. - pub mpf: Option<(usize, Vec)>, - /// The ISO 21496-1 APP2 payload after its URN: 4 bytes (versions only) on a primary image - /// that has a gain map, the full metadata on the gain map image itself. - pub iso_gainmap: Option>, -} +pub(crate) type Markers = craft_metadata::JpegInspection; -impl Markers { - /// This image is a gain map (ISO 21496-1 metadata or Adobe `hdrgm` gain parameters), not a - /// picture: never a preview, never the image to show. - pub fn is_gain_map(&self) -> bool { - self.iso_gainmap.as_ref().is_some_and(|p| p.len() > 4) || self.xmp.as_deref().is_some_and(|x| x.contains("hdrgm:GainMapMax")) - } -} - -pub(crate) fn parse_markers(b: &[u8]) -> Option { - if !b.starts_with(&[0xFF, 0xD8]) { - return None; - } - let mut m = Markers::default(); - let mut icc_chunks: [Option<&[u8]>; 255] = [None; 255]; - let mut icc_total = None; - let mut p = 2; - while p + 4 <= b.len() { - if b[p] != 0xFF { - // Tolerate garbage between segments: resync on the next 0xFF. - p += 1; - continue; - } - let marker = b[p + 1]; - if marker == 0xFF { - p += 1; - continue; - } - if marker == 0xD8 || (0xD0..=0xD7).contains(&marker) || marker == 0x01 { - p += 2; - continue; - } - if marker == 0xD9 { - break; - } - if marker == 0xDA { - m.first_scan_components = b.get(p + 4).copied().unwrap_or(0); - break; - } - let len = u16::from_be_bytes([b[p + 2], b[p + 3]]) as usize; - if len < 2 { - return None; - } - let start = p.checked_add(4)?; - let declared_end = p.checked_add(2)?.checked_add(len)?; - let complete = declared_end <= b.len(); - let end = declared_end.min(b.len()); - let seg = b.get(start..end)?; - match marker { - 0xC0..=0xCF if marker != 0xC4 && marker != 0xC8 && marker != 0xCC && seg.len() >= 6 && m.components == 0 => { - m.precision = seg[0]; - m.sof = marker; - m.height = u16::from_be_bytes([seg[1], seg[2]]) as u32; - m.width = u16::from_be_bytes([seg[3], seg[4]]) as u32; - m.components = seg[5]; - } - 0xE1 => { - m.app1 = m.app1.saturating_add(1); - if seg.starts_with(b"Exif\0\0") && m.exif.is_none() { - m.exif = Some(seg[6..].to_vec()); - m.exif_offset = start + 6; - } else if let Some(x) = seg.strip_prefix(b"http://ns.adobe.com/xap/1.0/\0") - && m.xmp.is_none() - { - m.xmp = Some(String::from_utf8_lossy(x).trim_end_matches('\0').to_string()); - } - } - 0xE2 => { - if seg.starts_with(b"ICC_PROFILE\0") { - if !complete || seg.len() < 14 { - m.icc_invalid = true; - } else if let (Some(&sequence), Some(&total)) = (seg.get(12), seg.get(13)) { - if sequence == 0 || total == 0 || sequence > total || icc_total.is_some_and(|expected| expected != total) { - m.icc_invalid = true; - } else { - icc_total = Some(total); - let Some(slot) = icc_chunks.get_mut(usize::from(sequence - 1)) else { - m.icc_invalid = true; - p = declared_end; - continue; - }; - if slot.is_some() { - m.icc_invalid = true; - } else if let Some(data) = seg.get(14..) { - *slot = Some(data); - } else { - m.icc_invalid = true; - } - } - } else { - m.icc_invalid = true; - } - } else if seg.starts_with(b"MPF\0") && m.mpf.is_none() { - m.mpf = Some((start + 4, seg[4..].to_vec())); - } else if let Some(p) = seg.strip_prefix(crate::gainmap::ISO_URN) - && m.iso_gainmap.is_none() - { - m.iso_gainmap = Some(p.to_vec()); - } - } - 0xEE if seg.starts_with(b"Adobe") && seg.len() >= 12 => { - m.adobe_transform = Some(seg[11]); - } - _ => {} - } - p = declared_end; - } - if let Some(total) = icc_total { - let mut profile_len = 0usize; - for chunk in icc_chunks.iter().take(usize::from(total)) { - let Some(bytes) = chunk else { - m.icc_invalid = true; - break; - }; - let Some(next_len) = profile_len.checked_add(bytes.len()) else { - m.icc_invalid = true; - break; - }; - profile_len = next_len; - } - let maximum_len = usize::from(total).checked_mul(65_519); - if maximum_len.is_none_or(|maximum| profile_len > maximum) { - m.icc_invalid = true; - } - if !m.icc_invalid { - let mut profile = Vec::with_capacity(profile_len); - for bytes in icc_chunks.iter().take(usize::from(total)).flatten() { - profile.extend_from_slice(bytes); - } - m.icc = Some(profile); - } - } - Some(m) +pub(crate) fn parse_markers(bytes: &[u8]) -> Option { + craft_metadata::inspect_jpeg(bytes) } pub(crate) fn decode(bytes: &[u8], opts: &DecodeOptions) -> Result { From 0bcf61140ef664dca38545b7f61f534fd27fd7b9 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 16:27:31 +0000 Subject: [PATCH 2/9] Include JPEG encoder notices --- NOTICE | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) diff --git a/NOTICE b/NOTICE index 39eb49db2c..e8576d71ee 100644 --- a/NOTICE +++ b/NOTICE @@ -335,3 +335,127 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +JPEG encoding dependency: jpeg-encoder 0.6.1 + +Source: https://crates.io/crates/jpeg-encoder/0.6.1 +Declared license: (MIT OR Apache-2.0) AND IJG. +This software is based in part on the work of the Independent JPEG Group. + +The MIT license and unaltered upstream IJG and SIMD notices follow. The Apache-2.0 +alternative is also retained in licenses/jpeg-encoder-0.6.1 at the repository root +(https://github.com/storytold/craft-libs/tree/main/licenses/jpeg-encoder-0.6.1). +The dependency is used unmodified; no encoder implementation is vendored here. + +LICENSE-MIT + +Copyright (c) 2021 Volker Ströbel + +Permission is hereby granted, free of charge, to any +person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the +Software without restriction, including without +limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice +shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF +ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR +IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. +Original src/fdct.rs opening notice + +/* + * Ported from mozjpeg to rust + * + * This file was part of the Independent JPEG Group's software: + * Copyright (C) 1991-1996, Thomas G. Lane. + * libjpeg-turbo Modifications: + * Copyright (C) 2015, 2020, D. R. Commander. + * + * Conditions of distribution and use: + * In plain English: + * + * 1. We don't promise that this software works. (But if you find any bugs, + * please let us know!) + * 2. You can use this software for whatever you want. You don't have to pay us. + * 3. You may not pretend that you wrote this software. If you use it in a + * program, you must acknowledge somewhere in your documentation that + * you've used the IJG code. + * + * In legalese: + * + * The authors make NO WARRANTY or representation, either express or implied, + * with respect to this software, its quality, accuracy, merchantability, or + * fitness for a particular purpose. This software is provided "AS IS", and you, + * its user, assume the entire risk as to its quality and accuracy. + * + * This software is copyright (C) 1991-2020, Thomas G. Lane, Guido Vollbeding. + * All Rights Reserved except as specified below. + * + * Permission is hereby granted to use, copy, modify, and distribute this + * software (or portions thereof) for any purpose, without fee, subject to these + * conditions: + * (1) If any part of the source code for this software is distributed, then this + * README file must be included, with this copyright and no-warranty notice + * unaltered; and any additions, deletions, or changes to the original files + * must be clearly indicated in accompanying documentation. + * (2) If only executable code is distributed, then the accompanying + * documentation must state that "this software is based in part on the work of + * the Independent JPEG Group". + * (3) Permission for use of this software is granted only if the user accepts + * full responsibility for any undesirable consequences; the authors accept + * NO LIABILITY for damages of any kind. + * + * These conditions apply to any software derived from or based on the IJG code, + * not just to the unmodified library. If you use our work, you ought to + * acknowledge us. + * + * Permission is NOT granted for the use of any IJG author's name or company name + * in advertising or publicity relating to this software or products derived from + * it. This software may be referred to only as "the Independent JPEG Group's + * software". + * + * We specifically permit and encourage the use of this software as the basis of + * commercial products, provided that all warranty or liability claims are + * assumed by the product vendor. + * + * This file contains a slower but more accurate integer implementation of the + * forward DCT (Discrete Cosine Transform). + * + * A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT + * on each column. Direct algorithms are also available, but they are + * much more complex and seem not to be any faster when reduced to code. + * + * This implementation is based on an algorithm described in + * C. Loeffler, A. Ligtenberg and G. Moschytz, "Practical Fast 1-D DCT + * Algorithms with 11 Multiplications", Proc. Int'l. Conf. on Acoustics, + * Speech, and Signal Processing 1989 (ICASSP '89), pp. 988-991. + * The primary algorithm described there uses 11 multiplies and 29 adds. + * We use their alternate method with 12 multiplies and 32 adds. + * The advantage of this method is that no data path contains more than one + * multiplication; this allows a very simple and accurate implementation in + * scaled fixed-point arithmetic, with a minimal number of shifts. + */ + +Original src/avx2/fdct.rs opening notice + +/* + * Ported from mozjpeg / jfdctint-avx2.asm to rust + * Copyright 2009 Pierre Ossman for Cendio AB + * Copyright (C) 2009, 2016, 2018, 2020, D. R. Commander. + * + * Based on the x86 SIMD extension for IJG JPEG library + * Copyright (C) 1999-2006, MIYASAKA Masaru. + */ From 30025788289d81902ab99f9b8b330d91f0053cc8 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 16:28:36 +0000 Subject: [PATCH 3/9] Pin JPEG inspection regression coverage --- Cargo.lock | 10 +++++----- Cargo.toml | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 737de69d5b..956517c4dc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1307,11 +1307,11 @@ dependencies = [ [[package]] name = "craft-metadata" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=091baf624fcaa67ad740c2ea9d6df3216b4bddc7#091baf624fcaa67ad740c2ea9d6df3216b4bddc7" +source = "git+https://github.com/storytold/craft-libs?rev=c97bc006df861d97d5da6f0db387693ab5592a65#c97bc006df861d97d5da6f0db387693ab5592a65" dependencies = [ "brotli-decompressor 6.0.1", "chrono", - "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=091baf624fcaa67ad740c2ea9d6df3216b4bddc7)", + "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=c97bc006df861d97d5da6f0db387693ab5592a65)", "quick-xml 0.41.0", "serde", ] @@ -1360,7 +1360,7 @@ dependencies = [ [[package]] name = "craft-tiff" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=091baf624fcaa67ad740c2ea9d6df3216b4bddc7#091baf624fcaa67ad740c2ea9d6df3216b4bddc7" +source = "git+https://github.com/storytold/craft-libs?rev=c97bc006df861d97d5da6f0db387693ab5592a65#c97bc006df861d97d5da6f0db387693ab5592a65" dependencies = [ "serde", "thiserror 2.0.21", @@ -3854,7 +3854,7 @@ dependencies = [ "craft-heif", "craft-image-codecs", "craft-jxl", - "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=091baf624fcaa67ad740c2ea9d6df3216b4bddc7)", + "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=c97bc006df861d97d5da6f0db387693ab5592a65)", "craft-psd", "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18)", "dhat", @@ -4090,7 +4090,7 @@ version = "0.21.1" dependencies = [ "chrono", "craft-heif", - "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=091baf624fcaa67ad740c2ea9d6df3216b4bddc7)", + "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=c97bc006df861d97d5da6f0db387693ab5592a65)", "craft-psd", "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18)", "lightcraft-geom", diff --git a/Cargo.toml b/Cargo.toml index 02ec034da6..d7bbeb954f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ craft-cms = { git = "https://github.com/storytold/craft-libs", rev = "f0f4758c01 craft-gif = { git = "https://github.com/storytold/craft-libs", rev = "b77af389f30bb10de10d8436ca9b39fe94e3bb67", features = ["frames"] } craft-jxl = { git = "https://github.com/storytold/craft-libs", rev = "b77af389f30bb10de10d8436ca9b39fe94e3bb67", default-features = false, features = ["decode", "encode"] } # Photo metadata: EXIF, IPTC-IIM, XMP packets and GPX track logs (craft-libs#949) -craft-metadata = { git = "https://github.com/storytold/craft-libs", rev = "091baf624fcaa67ad740c2ea9d6df3216b4bddc7" } +craft-metadata = { git = "https://github.com/storytold/craft-libs", rev = "c97bc006df861d97d5da6f0db387693ab5592a65" } craft-image-codecs = { git = "https://github.com/storytold/craft-libs", rev = "f0f4758c01581d79577b9bf5046c06f4e77b1f18" } craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "f0f4758c01581d79577b9bf5046c06f4e77b1f18" } # craft-update: app-specific pretend versions apply to startup and manual checks. From c3ed49a575653fc52f77c0132f5a7ec2c4c9e40f Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 16:30:37 +0000 Subject: [PATCH 4/9] Use shared MPF index inspection --- Cargo.lock | 10 +++++----- Cargo.toml | 2 +- crates/codecs/src/jpeg.rs | 34 ++-------------------------------- 3 files changed, 8 insertions(+), 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 956517c4dc..e42376c6ce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1307,11 +1307,11 @@ dependencies = [ [[package]] name = "craft-metadata" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=c97bc006df861d97d5da6f0db387693ab5592a65#c97bc006df861d97d5da6f0db387693ab5592a65" +source = "git+https://github.com/storytold/craft-libs?rev=591061efb488727cb4a38cbb10cb861dec0bc832#591061efb488727cb4a38cbb10cb861dec0bc832" dependencies = [ "brotli-decompressor 6.0.1", "chrono", - "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=c97bc006df861d97d5da6f0db387693ab5592a65)", + "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=591061efb488727cb4a38cbb10cb861dec0bc832)", "quick-xml 0.41.0", "serde", ] @@ -1360,7 +1360,7 @@ dependencies = [ [[package]] name = "craft-tiff" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=c97bc006df861d97d5da6f0db387693ab5592a65#c97bc006df861d97d5da6f0db387693ab5592a65" +source = "git+https://github.com/storytold/craft-libs?rev=591061efb488727cb4a38cbb10cb861dec0bc832#591061efb488727cb4a38cbb10cb861dec0bc832" dependencies = [ "serde", "thiserror 2.0.21", @@ -3854,7 +3854,7 @@ dependencies = [ "craft-heif", "craft-image-codecs", "craft-jxl", - "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=c97bc006df861d97d5da6f0db387693ab5592a65)", + "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=591061efb488727cb4a38cbb10cb861dec0bc832)", "craft-psd", "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18)", "dhat", @@ -4090,7 +4090,7 @@ version = "0.21.1" dependencies = [ "chrono", "craft-heif", - "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=c97bc006df861d97d5da6f0db387693ab5592a65)", + "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=591061efb488727cb4a38cbb10cb861dec0bc832)", "craft-psd", "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18)", "lightcraft-geom", diff --git a/Cargo.toml b/Cargo.toml index d7bbeb954f..6754aad6c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ craft-cms = { git = "https://github.com/storytold/craft-libs", rev = "f0f4758c01 craft-gif = { git = "https://github.com/storytold/craft-libs", rev = "b77af389f30bb10de10d8436ca9b39fe94e3bb67", features = ["frames"] } craft-jxl = { git = "https://github.com/storytold/craft-libs", rev = "b77af389f30bb10de10d8436ca9b39fe94e3bb67", default-features = false, features = ["decode", "encode"] } # Photo metadata: EXIF, IPTC-IIM, XMP packets and GPX track logs (craft-libs#949) -craft-metadata = { git = "https://github.com/storytold/craft-libs", rev = "c97bc006df861d97d5da6f0db387693ab5592a65" } +craft-metadata = { git = "https://github.com/storytold/craft-libs", rev = "591061efb488727cb4a38cbb10cb861dec0bc832" } craft-image-codecs = { git = "https://github.com/storytold/craft-libs", rev = "f0f4758c01581d79577b9bf5046c06f4e77b1f18" } craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "f0f4758c01581d79577b9bf5046c06f4e77b1f18" } # craft-update: app-specific pretend versions apply to startup and manual checks. diff --git a/crates/codecs/src/jpeg.rs b/crates/codecs/src/jpeg.rs index a988da567c..b829e6a362 100644 --- a/crates/codecs/src/jpeg.rs +++ b/crates/codecs/src/jpeg.rs @@ -244,39 +244,9 @@ pub(crate) fn embedded_thumbnail(bytes: &[u8], max_edge: u32, min_edge: u32) -> /// MP type code of a gain map image (CIPA DC-007 entry attribute, low 24 bits). pub(crate) const MPF_GAIN_MAP: u32 = 0x05_0000; -/// An MPF-listed image other than the primary. -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub(crate) struct MpfEntry { - /// File offset and length of the image. - pub offset: usize, - pub len: usize, - /// MP type code (attribute low 24 bits). - pub kind: u32, -} - /// The MPF-listed images other than the primary. -pub(crate) fn mpf_images(m: &Markers) -> Vec { - let Some((base, data)) = &m.mpf else { return vec![] }; - let Some(t) = exif::Tiff::new(data) else { return vec![] }; - let Some(ifd) = t.first_ifd() else { return vec![] }; - let Some((entries, _)) = t.ifd(ifd) else { return vec![] }; - let Some(e) = entries.iter().find(|e| e.tag == 0xB002) else { return vec![] }; - let Some(list) = t.bytes(e) else { return vec![] }; - let mut out = Vec::new(); - for (i, rec) in list.as_chunks::<16>().0.iter().enumerate().take(16) { - if i == 0 { - continue; - } - let rd = |o: usize| { - let a = [rec[o], rec[o + 1], rec[o + 2], rec[o + 3]]; - if data.starts_with(b"II") { u32::from_le_bytes(a) } else { u32::from_be_bytes(a) } - }; - let (attr, size, off) = (rd(0), rd(4) as usize, rd(8) as usize); - if size > 0 && off > 0 { - out.push(MpfEntry { offset: base.saturating_add(off), len: size, kind: attr & 0x00FF_FFFF }); - } - } - out +pub(crate) fn mpf_images(m: &Markers) -> Vec { + m.mpf.as_ref().map_or_else(Vec::new, |(base, data)| craft_metadata::mpf::images_from_index(data, *base)) } /// Decode to the file's 8-bit samples as stored (no colour management): 1 channel for greyscale From c50032401598627b52cd66599d94c8e6824df496 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 16:34:04 +0000 Subject: [PATCH 5/9] Verify MPF index compatibility --- Cargo.lock | 10 +++++----- Cargo.toml | 2 +- crates/codecs/src/jpeg.rs | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e42376c6ce..98d0d10626 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1307,11 +1307,11 @@ dependencies = [ [[package]] name = "craft-metadata" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=591061efb488727cb4a38cbb10cb861dec0bc832#591061efb488727cb4a38cbb10cb861dec0bc832" +source = "git+https://github.com/storytold/craft-libs?rev=149e74d739443d22fabb877745dad665f51c5eff#149e74d739443d22fabb877745dad665f51c5eff" dependencies = [ "brotli-decompressor 6.0.1", "chrono", - "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=591061efb488727cb4a38cbb10cb861dec0bc832)", + "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=149e74d739443d22fabb877745dad665f51c5eff)", "quick-xml 0.41.0", "serde", ] @@ -1360,7 +1360,7 @@ dependencies = [ [[package]] name = "craft-tiff" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=591061efb488727cb4a38cbb10cb861dec0bc832#591061efb488727cb4a38cbb10cb861dec0bc832" +source = "git+https://github.com/storytold/craft-libs?rev=149e74d739443d22fabb877745dad665f51c5eff#149e74d739443d22fabb877745dad665f51c5eff" dependencies = [ "serde", "thiserror 2.0.21", @@ -3854,7 +3854,7 @@ dependencies = [ "craft-heif", "craft-image-codecs", "craft-jxl", - "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=591061efb488727cb4a38cbb10cb861dec0bc832)", + "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=149e74d739443d22fabb877745dad665f51c5eff)", "craft-psd", "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18)", "dhat", @@ -4090,7 +4090,7 @@ version = "0.21.1" dependencies = [ "chrono", "craft-heif", - "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=591061efb488727cb4a38cbb10cb861dec0bc832)", + "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=149e74d739443d22fabb877745dad665f51c5eff)", "craft-psd", "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18)", "lightcraft-geom", diff --git a/Cargo.toml b/Cargo.toml index 6754aad6c5..33112fe8b7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ craft-cms = { git = "https://github.com/storytold/craft-libs", rev = "f0f4758c01 craft-gif = { git = "https://github.com/storytold/craft-libs", rev = "b77af389f30bb10de10d8436ca9b39fe94e3bb67", features = ["frames"] } craft-jxl = { git = "https://github.com/storytold/craft-libs", rev = "b77af389f30bb10de10d8436ca9b39fe94e3bb67", default-features = false, features = ["decode", "encode"] } # Photo metadata: EXIF, IPTC-IIM, XMP packets and GPX track logs (craft-libs#949) -craft-metadata = { git = "https://github.com/storytold/craft-libs", rev = "591061efb488727cb4a38cbb10cb861dec0bc832" } +craft-metadata = { git = "https://github.com/storytold/craft-libs", rev = "149e74d739443d22fabb877745dad665f51c5eff" } craft-image-codecs = { git = "https://github.com/storytold/craft-libs", rev = "f0f4758c01581d79577b9bf5046c06f4e77b1f18" } craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "f0f4758c01581d79577b9bf5046c06f4e77b1f18" } # craft-update: app-specific pretend versions apply to startup and manual checks. diff --git a/crates/codecs/src/jpeg.rs b/crates/codecs/src/jpeg.rs index b829e6a362..9f6fc9506a 100644 --- a/crates/codecs/src/jpeg.rs +++ b/crates/codecs/src/jpeg.rs @@ -275,6 +275,42 @@ pub(crate) fn decode_codes8(bytes: &[u8]) -> Result<(usize, usize, usize, Vec Vec { + let Some(t) = exif::Tiff::new(data) else { return vec![] }; + let Some(ifd) = t.first_ifd() else { return vec![] }; + let Some((entries, _)) = t.ifd(ifd) else { return vec![] }; + let Some(e) = entries.iter().find(|e| e.tag == 0xb002) else { return vec![] }; + let Some(list) = t.bytes(e) else { return vec![] }; + list.as_chunks::<16>() + .0 + .iter() + .enumerate() + .take(16) + .skip(1) + .filter_map(|(_, rec)| { + let rd = |i| { + let b = [rec[i], rec[i + 1], rec[i + 2], rec[i + 3]]; + if data.starts_with(b"II") { u32::from_le_bytes(b) } else { u32::from_be_bytes(b) } + }; + let (attr, len, off) = (rd(0), rd(4) as usize, rd(8) as usize); + (len > 0 && off > 0).then_some(craft_metadata::mpf::MpfImage { offset: base.saturating_add(off), len, kind: attr & 0x00ff_ffff }) + }) + .collect() + } + let file = craft_metadata::mpf::write(&[0xff, 0xd8, 0xff, 0xd9], &[(0x050000, &[0xff, 0xd8, 0xff, 0xd9])]).unwrap(); + let m = parse_markers(&file).unwrap(); + let (base, data) = m.mpf.unwrap(); + for at in 0..data.len() { + for value in [0u8, 0xff] { + let mut altered = data.clone(); + altered[at] = value; + assert_eq!(craft_metadata::mpf::images_from_index(&altered, base), previous(base, &altered), "mutation at {at}, value {value}"); + } + } + } + #[test] fn container_fallback_matches_tagged_jpeg_before_resizing_and_keeps_own_metadata() { use crate::{ChromaSubsampling, EncodeImage, EncodeMeta, NamedSpace, Samples, SpaceOrigin, encode_jpeg}; From 6c734c0fce62819d2696b46fcd84023b1b01561e Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 16:45:14 +0000 Subject: [PATCH 6/9] Use shared MPF writer for gain maps --- crates/codecs/src/gainmap.rs | 45 ++---------------------------------- 1 file changed, 2 insertions(+), 43 deletions(-) diff --git a/crates/codecs/src/gainmap.rs b/crates/codecs/src/gainmap.rs index 4a6f485818..b2b8fa2cf8 100644 --- a/crates/codecs/src/gainmap.rs +++ b/crates/codecs/src/gainmap.rs @@ -16,33 +16,6 @@ pub use craft_gainmap::{GainImage, GainMapMeta, GainMapOptions, ISO_URN, apply, use crate::encode::{EncodeImage, EncodeMeta, Samples, jpeg_app_segments, xmp_segment}; use crate::{ChromaSubsampling, Error, Format, Result, jpeg, jpeg_par}; -/// Offsets within the MPF payload (from "MPF\0"): the endian field, then the index IFD (3 tags). -const MPF_ENTRIES_FROM_ENDIAN: usize = 8 + 2 + 3 * 12 + 4; - -/// The primary image's MPF payload, entry sizes and offset to be patched once the file exists. -fn mpf_placeholder() -> Vec { - let mut p = b"MPF\0MM".to_vec(); - p.extend_from_slice(&42u16.to_be_bytes()); - p.extend_from_slice(&8u32.to_be_bytes()); // first IFD - p.extend_from_slice(&3u16.to_be_bytes()); - let tag = |p: &mut Vec, tag: u16, ty: u16, count: u32, value: [u8; 4]| { - p.extend_from_slice(&tag.to_be_bytes()); - p.extend_from_slice(&ty.to_be_bytes()); - p.extend_from_slice(&count.to_be_bytes()); - p.extend_from_slice(&value); - }; - tag(&mut p, 0xB000, 7, 4, *b"0100"); // MPFVersion - tag(&mut p, 0xB001, 4, 1, 2u32.to_be_bytes()); // NumberOfImages - tag(&mut p, 0xB002, 7, 32, (MPF_ENTRIES_FROM_ENDIAN as u32).to_be_bytes()); // MPEntry - p.extend_from_slice(&0u32.to_be_bytes()); // no next IFD - // entry 0: baseline primary (0x030000) flagged as the representative image (bit 29) - for attr in [0x2003_0000u32, jpeg::MPF_GAIN_MAP] { - p.extend_from_slice(&attr.to_be_bytes()); - p.extend_from_slice(&[0; 12]); // size, offset, two dependent-image entries - } - p -} - /// Encode a gain map JPEG: `base` (8-bit SDR, 3 or 4 channels, colour-managed by `meta.icc`) and /// its gain map, both at `quality`. `meta.xmp` is kept, with the gain map container added. pub fn encode_jpeg(base: &EncodeImage, gain: &GainImage, m: &GainMapMeta, quality: u8, sub: ChromaSubsampling, meta: &EncodeMeta) -> Result> { @@ -75,22 +48,8 @@ pub fn encode_jpeg(base: &EncodeImage, gain: &GainImage, m: &GainMapMeta, qualit let xmp = craft_gainmap::primary_xmp(meta.xmp, gain_jpeg.len()); let mut segs = jpeg_app_segments(&EncodeMeta { xmp: Some(&xmp), ..*meta })?; segs.push((0xE2, craft_gainmap::primary_iso_marker())); - segs.push((0xE2, mpf_placeholder())); - let mut primary = jpeg_par::encode(data, w, h, base.channels as usize, quality, sub, &segs); - - // patch the MPF index: sizes, and the gain map's offset from the MPF endian field - let markers = jpeg::parse_markers(&primary).ok_or_else(|| Error::Encode("gain map JPEG: primary image unreadable".into()))?; - let endian = markers.mpf.as_ref().map(|m| m.0).ok_or_else(|| Error::Encode("gain map JPEG: MPF segment missing".into()))?; - let entries = endian + MPF_ENTRIES_FROM_ENDIAN; - let (plen, glen) = (primary.len(), gain_jpeg.len()); - let fields = [(entries + 4, plen), (entries + 8, 0), (entries + 20, glen), (entries + 24, plen - endian)]; - for (at, v) in fields { - let v = u32::try_from(v).map_err(|_| Error::Encode("gain map JPEG larger than 4 GiB".into()))?; - let slot = primary.get_mut(at..at + 4).ok_or_else(|| Error::Encode("gain map JPEG: truncated MPF segment".into()))?; - slot.copy_from_slice(&v.to_be_bytes()); - } - primary.extend_from_slice(&gain_jpeg); - Ok(primary) + let primary = jpeg_par::encode(data, w, h, base.channels as usize, quality, sub, &segs); + craft_metadata::mpf::write(&primary, &[(jpeg::MPF_GAIN_MAP, &gain_jpeg)]).map_err(|error| Error::Encode(format!("gain map JPEG: {error}"))) } /// The gain map of a gain map JPEG. From 58c6741b16b547e80da92ee68a5758c9e6123768 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 17:49:19 +0000 Subject: [PATCH 7/9] Align metadata and TIFF dependency revisions --- Cargo.lock | 16 ++++++++-------- Cargo.toml | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 98d0d10626..09c6cf5b8a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1199,7 +1199,7 @@ dependencies = [ [[package]] name = "craft-crw" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18#f0f4758c01581d79577b9bf5046c06f4e77b1f18" +source = "git+https://github.com/storytold/craft-libs?rev=149e74d739443d22fabb877745dad665f51c5eff#149e74d739443d22fabb877745dad665f51c5eff" dependencies = [ "thiserror 2.0.21", ] @@ -1342,12 +1342,12 @@ dependencies = [ [[package]] name = "craft-raw" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18#f0f4758c01581d79577b9bf5046c06f4e77b1f18" +source = "git+https://github.com/storytold/craft-libs?rev=149e74d739443d22fabb877745dad665f51c5eff#149e74d739443d22fabb877745dad665f51c5eff" dependencies = [ "chrono", "craft-crw", - "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18)", - "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18)", + "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=149e74d739443d22fabb877745dad665f51c5eff)", + "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=149e74d739443d22fabb877745dad665f51c5eff)", "jxl-oxide", "miniz_oxide 0.9.1", "rayon", @@ -3856,7 +3856,7 @@ dependencies = [ "craft-jxl", "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=149e74d739443d22fabb877745dad665f51c5eff)", "craft-psd", - "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18)", + "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=149e74d739443d22fabb877745dad665f51c5eff)", "dhat", "jxl-oxide", "lightcraft-color", @@ -3933,7 +3933,7 @@ dependencies = [ "chrono", "craft-docpath", "craft-heif", - "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18)", + "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=149e74d739443d22fabb877745dad665f51c5eff)", "crc32fast", "fs4", "harfrust 0.13.3", @@ -4092,7 +4092,7 @@ dependencies = [ "craft-heif", "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=149e74d739443d22fabb877745dad665f51c5eff)", "craft-psd", - "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18)", + "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=149e74d739443d22fabb877745dad665f51c5eff)", "lightcraft-geom", "proptest", "serde", @@ -4147,7 +4147,7 @@ dependencies = [ "chrono", "craft-image-codecs", "craft-raw", - "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18)", + "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=149e74d739443d22fabb877745dad665f51c5eff)", "dhat", "lightcraft-color", "lightcraft-geom", diff --git a/Cargo.toml b/Cargo.toml index 33112fe8b7..4f58439440 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,10 +38,10 @@ lightcraft-wincolor = { path = "crates/wincolor" } lightcraft-color = { path = "crates/color" } lightcraft-raster = { path = "crates/raster" } # TIFF/IFD: the shared reader and writer (moved from crates/tiff; craft-libs#783). -craft-tiff = { git = "https://github.com/storytold/craft-libs", rev = "f0f4758c01581d79577b9bf5046c06f4e77b1f18" } +craft-tiff = { git = "https://github.com/storytold/craft-libs", rev = "149e74d739443d22fabb877745dad665f51c5eff" } # Camera raw files, the format layer: every maker but CR3, ARW, RAF, RW2 and ORF (craft-libs#862 and the maker PRs). # On the same commit as craft-tiff: its errors and IFDs are shared. -craft-raw = { git = "https://github.com/storytold/craft-libs", rev = "f0f4758c01581d79577b9bf5046c06f4e77b1f18" } +craft-raw = { git = "https://github.com/storytold/craft-libs", rev = "149e74d739443d22fabb877745dad665f51c5eff" } lightcraft-raw = { path = "crates/raw" } lightcraft-codecs = { path = "crates/codecs" } lightcraft-meta = { path = "crates/meta" } From 636dae1021de88d74c06661bb99f6f8a0a5ffcb5 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 17:26:54 -0500 Subject: [PATCH 8/9] Include sample-to-chunk mappings in CR3 fixtures --- crates/raw/tests/it/cr3_variants.rs | 5 ++++- crates/raw/tests/it/crx_properties.rs | 5 ++++- crates/raw/tests/it/robust.rs | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/crates/raw/tests/it/cr3_variants.rs b/crates/raw/tests/it/cr3_variants.rs index 54d7f8d9f2..1fe40e8900 100644 --- a/crates/raw/tests/it/cr3_variants.rs +++ b/crates/raw/tests/it/cr3_variants.rs @@ -101,7 +101,10 @@ fn cr3_file(coding: &[u8], sample: &[u8]) -> Vec { let mut co64 = vec![0u8; 4]; co64.extend(1u32.to_be_bytes()); // entry count co64.extend([0u8; 8]); // sample offset, patched once the layout is known - let tables = [box_bytes(b"stsd", &stsd), box_bytes(b"stsz", &stsz), box_bytes(b"co64", &co64)].concat(); + // One sample in chunk 1, using sample description 1. The shared parser + // deliberately refuses sample access without this mapping. + let stsc: Vec = [0u32, 1, 1, 1, 1].into_iter().flat_map(u32::to_be_bytes).collect(); + let tables = [box_bytes(b"stsd", &stsd), box_bytes(b"stsc", &stsc), box_bytes(b"stsz", &stsz), box_bytes(b"co64", &co64)].concat(); let trak = box_bytes(b"trak", &box_bytes(b"mdia", &box_bytes(b"minf", &box_bytes(b"stbl", &tables)))); let mut file = box_bytes(b"ftyp", b"crx \0\0\0\x01crx isom"); file.extend(box_bytes(b"moov", &trak)); diff --git a/crates/raw/tests/it/crx_properties.rs b/crates/raw/tests/it/crx_properties.rs index 30ff2dd195..aed870bc1d 100644 --- a/crates/raw/tests/it/crx_properties.rs +++ b/crates/raw/tests/it/crx_properties.rs @@ -399,7 +399,10 @@ fn track_box(entry: &[u8], offset: u64, size: u32) -> Vec { let mut co64 = vec![0u8; 4]; co64.extend(1u32.to_be_bytes()); co64.extend(offset.to_be_bytes()); - let tables = [box_bytes(b"stsd", &stsd), box_bytes(b"stsz", &stsz), box_bytes(b"co64", &co64)].concat(); + // One sample in chunk 1, using sample description 1. The shared parser + // deliberately refuses sample access without this mapping. + let stsc: Vec = [0u32, 1, 1, 1, 1].into_iter().flat_map(u32::to_be_bytes).collect(); + let tables = [box_bytes(b"stsd", &stsd), box_bytes(b"stsc", &stsc), box_bytes(b"stsz", &stsz), box_bytes(b"co64", &co64)].concat(); box_bytes(b"trak", &box_bytes(b"mdia", &box_bytes(b"minf", &box_bytes(b"stbl", &tables)))) } diff --git a/crates/raw/tests/it/robust.rs b/crates/raw/tests/it/robust.rs index 3cd54e47e9..c690afdf08 100644 --- a/crates/raw/tests/it/robust.rs +++ b/crates/raw/tests/it/robust.rs @@ -202,7 +202,10 @@ mod cr3 { let mut co64 = vec![0u8; 4]; co64.extend(1u32.to_be_bytes()); co64.extend(offset.to_be_bytes()); - let tables = [box_bytes(b"stsd", &stsd), box_bytes(b"stsz", &stsz), box_bytes(b"co64", &co64)].concat(); + // One sample in chunk 1, using sample description 1. The shared parser + // deliberately refuses sample access without this mapping. + let stsc: Vec = [0u32, 1, 1, 1, 1].into_iter().flat_map(u32::to_be_bytes).collect(); + let tables = [box_bytes(b"stsd", &stsd), box_bytes(b"stsc", &stsc), box_bytes(b"stsz", &stsz), box_bytes(b"co64", &co64)].concat(); box_bytes(b"trak", &box_bytes(b"mdia", &box_bytes(b"minf", &box_bytes(b"stbl", &tables)))) } From c3c8e93b20ded69eaa4c2b9bfbfcab7d2340fe14 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Wed, 18 Nov 2026 09:10:59 -0500 Subject: [PATCH 9/9] fix(codecs): gate the legacy EXIF walker to tests Merging main left the app-owned TIFF walker without non-test callers, so clippy's dead_code lint failed the gate. The walker is still the oracle for the shared-summary compatibility test. --- crates/codecs/src/exif.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/codecs/src/exif.rs b/crates/codecs/src/exif.rs index 79f4d52753..1f8496af91 100644 --- a/crates/codecs/src/exif.rs +++ b/crates/codecs/src/exif.rs @@ -2,12 +2,14 @@ //! thumbnail, colour-space hint). Full EXIF parsing lives in `lightcraft-meta`. /// Byte-order aware reader over a TIFF-structured blob. +#[cfg(test)] #[derive(Clone, Copy)] pub(crate) struct Tiff<'a> { pub data: &'a [u8], le: bool, } +#[cfg(test)] #[derive(Clone, Copy, Debug)] pub(crate) struct Entry { pub tag: u16, @@ -17,6 +19,7 @@ pub(crate) struct Entry { pub value_pos: usize, } +#[cfg(test)] impl<'a> Tiff<'a> { pub fn new(data: &'a [u8]) -> Option> { let le = match data.get(0..2)? {