From e4edd61b62f62b057646fe3636cb21e35559e820 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 15:41:52 +0000 Subject: [PATCH 01/14] Use shared PNG header and color inspection --- Cargo.lock | 54 +++++++++++--- Cargo.toml | 2 +- NOTICE | 124 +++++++++++++++++++++++++++++++++ crates/codecs/src/png_codec.rs | 112 ++++------------------------- 4 files changed, 182 insertions(+), 110 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 04c07b04f1..499510e2f5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1266,13 +1266,15 @@ dependencies = [ [[package]] name = "craft-image-codecs" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18#f0f4758c01581d79577b9bf5046c06f4e77b1f18" +source = "git+https://github.com/storytold/craft-libs?rev=188d935887cb1ea2b9f058e8063718b03e1f27ee#188d935887cb1ea2b9f058e8063718b03e1f27ee" dependencies = [ "craft-jpeg", - "craft-metadata", + "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=188d935887cb1ea2b9f058e8063718b03e1f27ee)", + "crc32fast", "exr", "flate2", "half", + "hayro-jpeg2000", "image", "image-webp", "jpeg-encoder", @@ -1289,7 +1291,7 @@ dependencies = [ [[package]] name = "craft-jpeg" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18#f0f4758c01581d79577b9bf5046c06f4e77b1f18" +source = "git+https://github.com/storytold/craft-libs?rev=188d935887cb1ea2b9f058e8063718b03e1f27ee#188d935887cb1ea2b9f058e8063718b03e1f27ee" dependencies = [ "thiserror 2.0.21", ] @@ -1304,6 +1306,18 @@ dependencies = [ "thiserror 2.0.21", ] +[[package]] +name = "craft-metadata" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=188d935887cb1ea2b9f058e8063718b03e1f27ee#188d935887cb1ea2b9f058e8063718b03e1f27ee" +dependencies = [ + "brotli-decompressor 6.0.1", + "chrono", + "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=188d935887cb1ea2b9f058e8063718b03e1f27ee)", + "quick-xml 0.41.0", + "serde", +] + [[package]] name = "craft-metadata" version = "0.1.0" @@ -1311,7 +1325,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 +1348,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 +1359,15 @@ dependencies = [ "zune-jpeg", ] +[[package]] +name = "craft-tiff" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=188d935887cb1ea2b9f058e8063718b03e1f27ee#188d935887cb1ea2b9f058e8063718b03e1f27ee" +dependencies = [ + "serde", + "thiserror 2.0.21", +] + [[package]] name = "craft-tiff" version = "0.1.0" @@ -3033,6 +3056,15 @@ dependencies = [ "foldhash 0.2.0", ] +[[package]] +name = "hayro-jpeg2000" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c75ab947623ef4ccaa7acf0579edf7cbb5a73838e3839a7be73335e522f433a1" +dependencies = [ + "fearless_simd", +] + [[package]] name = "heck" version = "0.5.0" @@ -3834,7 +3866,7 @@ dependencies = [ "craft-image-codecs", "craft-jxl", "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 +3943,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 +4100,9 @@ version = "0.21.1" dependencies = [ "chrono", "craft-heif", - "craft-metadata", + "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18)", "craft-psd", - "craft-tiff", + "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18)", "lightcraft-geom", "proptest", "serde", @@ -4125,7 +4157,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..7f458df6e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ craft-gif = { git = "https://github.com/storytold/craft-libs", rev = "b77af389f3 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-image-codecs = { git = "https://github.com/storytold/craft-libs", rev = "f0f4758c01581d79577b9bf5046c06f4e77b1f18" } +craft-image-codecs = { git = "https://github.com/storytold/craft-libs", rev = "188d935887cb1ea2b9f058e8063718b03e1f27ee" } craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "f0f4758c01581d79577b9bf5046c06f4e77b1f18" } # craft-update: app-specific pretend versions apply to startup and manual checks. craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "6e03f65bf45181db77ba6229716e6624db9eb25b", features = ["egui"] } 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. + */ diff --git a/crates/codecs/src/png_codec.rs b/crates/codecs/src/png_codec.rs index ae79db4f04..11147dffd3 100644 --- a/crates/codecs/src/png_codec.rs +++ b/crates/codecs/src/png_codec.rs @@ -16,9 +16,7 @@ fn err(e: impl std::fmt::Display) -> Error { } pub(crate) fn decode(bytes: &[u8], opts: &DecodeOptions) -> Result { - if bytes.starts_with(b"\x89PNG\r\n\x1a\n") && bytes.get(12..16) == Some(b"IHDR") && bytes.len() >= 24 { - let w = u32::from_be_bytes([bytes[16], bytes[17], bytes[18], bytes[19]]); - let h = u32::from_be_bytes([bytes[20], bytes[21], bytes[22], bytes[23]]); + if let Some((w, h)) = craft_image_codecs::png_probe::declared_dimensions(bytes) { check_size(F, w as u64, h as u64, opts)?; } let ic_opts = craft_image_codecs::DecodeOptions { @@ -52,106 +50,24 @@ pub(crate) fn decode(bytes: &[u8], opts: &DecodeOptions) -> Result { finish(F, raw, meta, (w, h), opts) } -/// Stored dimensions and EXIF orientation (`eXIf`, wherever it is) from the chunk headers, without -/// inflating the image data. Refused, as a decode would refuse it: an invalid IHDR, an indexed -/// image without a palette, no IDAT, or a file that ends before the chunk after the last IDAT -/// begins (truncated image data). Chunk CRCs and the deflate stream are not checked. +/// Stored dimensions and EXIF orientation without inflating pixels. pub(crate) fn header(b: &[u8]) -> Result<(u32, u32, u16)> { - if !b.starts_with(b"\x89PNG\r\n\x1a\n") { - return Err(err("bad signature")); - } - let be32 = |p: usize| b.get(p..p.checked_add(4)?).map(|v| u32::from_be_bytes([v[0], v[1], v[2], v[3]])); - if be32(8) != Some(13) || b.get(12..16) != Some(b"IHDR") { - return Err(err("missing IHDR")); - } - let ihdr = b.get(16..29).ok_or_else(|| err("truncated IHDR"))?; - let (w, h) = (u32::from_be_bytes([ihdr[0], ihdr[1], ihdr[2], ihdr[3]]), u32::from_be_bytes([ihdr[4], ihdr[5], ihdr[6], ihdr[7]])); - let (depth, color, compression, filter, interlace) = (ihdr[8], ihdr[9], ihdr[10], ihdr[11], ihdr[12]); - if w > i32::MAX as u32 || h > i32::MAX as u32 { - return Err(err("dimensions out of range")); - } - check_size(F, w as u64, h as u64, &DecodeOptions::default())?; - let depth_ok = match color { - 0 => matches!(depth, 1 | 2 | 4 | 8 | 16), - 3 => matches!(depth, 1 | 2 | 4 | 8), - 2 | 4 | 6 => matches!(depth, 8 | 16), - _ => false, - }; - if !depth_ok || compression != 0 || filter != 0 || interlace > 1 { - return Err(err("invalid IHDR")); - } - let (mut p, mut palette, mut idat, mut after_idat, mut exif) = (8usize, false, false, false, None); - while let Some(len) = be32(p) { - let Some(kind) = p.checked_add(4).and_then(|k| b.get(k..k.checked_add(4)?)) else { break }; - if idat && kind != b"IDAT" { - // a chunk follows the image data: the IDAT run is complete - after_idat = true; - } - if kind == b"IEND" { - break; - } - let start = p.saturating_add(8); - let data = (len <= i32::MAX as u32).then(|| start.checked_add(len as usize).and_then(|end| b.get(start..end))).flatten(); - let Some(data) = data else { - if after_idat { - break; // a damaged chunk after the image data: a decode ignores it too + let (w, h, orientation) = + craft_image_codecs::png_probe::header_with_max_pixels(b, DecodeOptions::default().max_pixels).map_err(|error| match error { + craft_image_codecs::CodecError::LimitExceeded(_) => { + let (w, h) = craft_image_codecs::png_probe::declared_dimensions(b).unwrap_or((0, 0)); + Error::TooLarge(w as u64, h as u64) } - return Err(err("truncated")); - }; - match kind { - b"PLTE" => palette = true, - b"IDAT" if after_idat => {} // a stray IDAT after other chunks: the first run is the image - b"IDAT" => { - if color == 3 && !palette { - return Err(err("indexed image without a palette")); - } - idat = true; - } - b"eXIf" if exif.is_none() => exif = Some(data.strip_prefix(b"Exif\0\0").unwrap_or(data)), - _ => {} - } - p = start.saturating_add(data.len()).saturating_add(4); - } - if !idat { - return Err(err("no image data")); - } - if !after_idat { - return Err(err("truncated image data")); - } - Ok((w, h, exif.map(crate::exif::summarize).unwrap_or_default().orientation.unwrap_or(1))) + other => err(other), + })?; + Ok((w, h, orientation)) } fn container_hint_from_chunks(b: &[u8]) -> Option { - if !b.starts_with(b"\x89PNG\r\n\x1a\n") { - return None; - } - let mut has_srgb = false; - let mut gamma: Option = None; - let mut chrm: Option<[f64; 8]> = None; - let mut p = 8usize; - while let Some(len_bytes) = b.get(p..p + 4) { - let len = u32::from_be_bytes([len_bytes[0], len_bytes[1], len_bytes[2], len_bytes[3]]) as usize; - let Some(kind) = b.get(p + 4..p + 8) else { break }; - let Some(payload) = b.get(p + 8..p + 8 + len) else { break }; - if kind == b"sRGB" { - has_srgb = true; - } else if kind == b"gAMA" && payload.len() == 4 { - let v = u32::from_be_bytes([payload[0], payload[1], payload[2], payload[3]]) as f32 / 100_000.0; - if v > 0.0 && v.is_finite() { - gamma = Some(v); - } - } else if kind == b"cHRM" && payload.len() == 32 { - let mut vals = [0.0f64; 8]; - for (i, dst) in vals.iter_mut().enumerate() { - let raw = i32::from_be_bytes([payload[i * 4], payload[i * 4 + 1], payload[i * 4 + 2], payload[i * 4 + 3]]); - *dst = raw as f64 / 100_000.0; - } - chrm = Some(vals); - } else if kind == b"IDAT" || kind == b"IEND" { - break; - } - p = p.saturating_add(12).saturating_add(len); - } + let chunks = craft_image_codecs::png_probe::color_chunks(b)?; + let has_srgb = chunks.srgb; + let gamma = chunks.gamma; + let chrm = chunks.chromaticities; if has_srgb { return Some(SourceSpace::named(NamedSpace::Srgb, SpaceOrigin::Container)); } From f65065448a7d8de273d993b806a11cf0c59a7392 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 17:08:35 +0000 Subject: [PATCH 02/14] Pin merged shared PNG inspection --- Cargo.lock | 12 ++++++------ Cargo.toml | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 499510e2f5..ad795b8783 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1266,10 +1266,10 @@ dependencies = [ [[package]] name = "craft-image-codecs" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=188d935887cb1ea2b9f058e8063718b03e1f27ee#188d935887cb1ea2b9f058e8063718b03e1f27ee" +source = "git+https://github.com/storytold/craft-libs?rev=b84bce6ef6635cf1ad84263310456a418d604fa6#b84bce6ef6635cf1ad84263310456a418d604fa6" dependencies = [ "craft-jpeg", - "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=188d935887cb1ea2b9f058e8063718b03e1f27ee)", + "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=b84bce6ef6635cf1ad84263310456a418d604fa6)", "crc32fast", "exr", "flate2", @@ -1291,7 +1291,7 @@ dependencies = [ [[package]] name = "craft-jpeg" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=188d935887cb1ea2b9f058e8063718b03e1f27ee#188d935887cb1ea2b9f058e8063718b03e1f27ee" +source = "git+https://github.com/storytold/craft-libs?rev=b84bce6ef6635cf1ad84263310456a418d604fa6#b84bce6ef6635cf1ad84263310456a418d604fa6" dependencies = [ "thiserror 2.0.21", ] @@ -1309,11 +1309,11 @@ dependencies = [ [[package]] name = "craft-metadata" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=188d935887cb1ea2b9f058e8063718b03e1f27ee#188d935887cb1ea2b9f058e8063718b03e1f27ee" +source = "git+https://github.com/storytold/craft-libs?rev=b84bce6ef6635cf1ad84263310456a418d604fa6#b84bce6ef6635cf1ad84263310456a418d604fa6" dependencies = [ "brotli-decompressor 6.0.1", "chrono", - "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=188d935887cb1ea2b9f058e8063718b03e1f27ee)", + "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=b84bce6ef6635cf1ad84263310456a418d604fa6)", "quick-xml 0.41.0", "serde", ] @@ -1362,7 +1362,7 @@ dependencies = [ [[package]] name = "craft-tiff" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=188d935887cb1ea2b9f058e8063718b03e1f27ee#188d935887cb1ea2b9f058e8063718b03e1f27ee" +source = "git+https://github.com/storytold/craft-libs?rev=b84bce6ef6635cf1ad84263310456a418d604fa6#b84bce6ef6635cf1ad84263310456a418d604fa6" dependencies = [ "serde", "thiserror 2.0.21", diff --git a/Cargo.toml b/Cargo.toml index 7f458df6e8..f6872dc92a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ craft-gif = { git = "https://github.com/storytold/craft-libs", rev = "b77af389f3 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-image-codecs = { git = "https://github.com/storytold/craft-libs", rev = "188d935887cb1ea2b9f058e8063718b03e1f27ee" } +craft-image-codecs = { git = "https://github.com/storytold/craft-libs", rev = "b84bce6ef6635cf1ad84263310456a418d604fa6" } craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "f0f4758c01581d79577b9bf5046c06f4e77b1f18" } # craft-update: app-specific pretend versions apply to startup and manual checks. craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "6e03f65bf45181db77ba6229716e6624db9eb25b", features = ["egui"] } From 567ee259a8d645ba19aa88cf75db8afc17206a0b Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 17:14:12 +0000 Subject: [PATCH 03/14] Preserve legacy PNG EXIF orientation behavior --- Cargo.lock | 12 ++++++------ Cargo.toml | 2 +- crates/codecs/src/png_codec.rs | 17 +++++++++++++++++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ad795b8783..7f64442692 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1266,10 +1266,10 @@ dependencies = [ [[package]] name = "craft-image-codecs" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=b84bce6ef6635cf1ad84263310456a418d604fa6#b84bce6ef6635cf1ad84263310456a418d604fa6" +source = "git+https://github.com/storytold/craft-libs?rev=c6f4f5115e6d7e5a53180f297c7cda8c5c4cb3c9#c6f4f5115e6d7e5a53180f297c7cda8c5c4cb3c9" dependencies = [ "craft-jpeg", - "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=b84bce6ef6635cf1ad84263310456a418d604fa6)", + "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=c6f4f5115e6d7e5a53180f297c7cda8c5c4cb3c9)", "crc32fast", "exr", "flate2", @@ -1291,7 +1291,7 @@ dependencies = [ [[package]] name = "craft-jpeg" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=b84bce6ef6635cf1ad84263310456a418d604fa6#b84bce6ef6635cf1ad84263310456a418d604fa6" +source = "git+https://github.com/storytold/craft-libs?rev=c6f4f5115e6d7e5a53180f297c7cda8c5c4cb3c9#c6f4f5115e6d7e5a53180f297c7cda8c5c4cb3c9" dependencies = [ "thiserror 2.0.21", ] @@ -1309,11 +1309,11 @@ dependencies = [ [[package]] name = "craft-metadata" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=b84bce6ef6635cf1ad84263310456a418d604fa6#b84bce6ef6635cf1ad84263310456a418d604fa6" +source = "git+https://github.com/storytold/craft-libs?rev=c6f4f5115e6d7e5a53180f297c7cda8c5c4cb3c9#c6f4f5115e6d7e5a53180f297c7cda8c5c4cb3c9" dependencies = [ "brotli-decompressor 6.0.1", "chrono", - "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=b84bce6ef6635cf1ad84263310456a418d604fa6)", + "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=c6f4f5115e6d7e5a53180f297c7cda8c5c4cb3c9)", "quick-xml 0.41.0", "serde", ] @@ -1362,7 +1362,7 @@ dependencies = [ [[package]] name = "craft-tiff" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=b84bce6ef6635cf1ad84263310456a418d604fa6#b84bce6ef6635cf1ad84263310456a418d604fa6" +source = "git+https://github.com/storytold/craft-libs?rev=c6f4f5115e6d7e5a53180f297c7cda8c5c4cb3c9#c6f4f5115e6d7e5a53180f297c7cda8c5c4cb3c9" dependencies = [ "serde", "thiserror 2.0.21", diff --git a/Cargo.toml b/Cargo.toml index f6872dc92a..ac0913663f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ craft-gif = { git = "https://github.com/storytold/craft-libs", rev = "b77af389f3 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-image-codecs = { git = "https://github.com/storytold/craft-libs", rev = "b84bce6ef6635cf1ad84263310456a418d604fa6" } +craft-image-codecs = { git = "https://github.com/storytold/craft-libs", rev = "c6f4f5115e6d7e5a53180f297c7cda8c5c4cb3c9" } craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "f0f4758c01581d79577b9bf5046c06f4e77b1f18" } # craft-update: app-specific pretend versions apply to startup and manual checks. craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "6e03f65bf45181db77ba6229716e6624db9eb25b", features = ["egui"] } diff --git a/crates/codecs/src/png_codec.rs b/crates/codecs/src/png_codec.rs index 11147dffd3..8f81527782 100644 --- a/crates/codecs/src/png_codec.rs +++ b/crates/codecs/src/png_codec.rs @@ -109,6 +109,23 @@ mod tests { /// A compressed text chunk is expanded by `png` through our own cap: an XMP document /// bigger than it is dropped, not inflated. Compressing an 8 MiB string is a few /// kilobytes — the reverse of what the unbounded `get_text()` path allowed. + #[test] + fn exif_orientation_mutation_parity() { + let image = craft_image_codecs::Image::from_u8(1, 1, craft_image_codecs::ChannelLayout::Gray, vec![0]).unwrap(); + let base = craft_image_codecs::encode(&image, craft_image_codecs::Format::Png, &craft_image_codecs::EncodeOptions::default()).unwrap(); + let exif = crate::exif::minimal_exif(6); + for at in 0..exif.len() { + for value in [0, 255] { + let mut data = exif.clone(); + data[at] = value; + let mut png = base.clone(); + let iend = png.len() - 12; + png.splice(iend..iend, png_chunk(*b"eXIf", &data)); + assert_eq!(super::header(&png).unwrap().2, crate::exif::summarize(&data).orientation.unwrap_or(1), "at {at}, value {value}"); + } + } + } + #[test] fn compressed_xmp_over_the_cap_is_dropped() { let out = png_with_compressed_xmp(&"x".repeat(8 << 20)); From 08c83c1e0aa630868df517df981253b65a30d725 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 17:20:44 +0000 Subject: [PATCH 04/14] Use shared legacy EXIF summary --- Cargo.lock | 15 ++++++++------- Cargo.toml | 4 ++-- crates/codecs/Cargo.toml | 1 + crates/codecs/src/exif.rs | 28 ++++++++-------------------- crates/codecs/src/png_codec.rs | 2 +- 5 files changed, 20 insertions(+), 30 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7f64442692..8e54612419 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1266,10 +1266,10 @@ dependencies = [ [[package]] name = "craft-image-codecs" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=c6f4f5115e6d7e5a53180f297c7cda8c5c4cb3c9#c6f4f5115e6d7e5a53180f297c7cda8c5c4cb3c9" +source = "git+https://github.com/storytold/craft-libs?rev=42abc84c82cd573e2fb0277298caffecb7bee905#42abc84c82cd573e2fb0277298caffecb7bee905" dependencies = [ "craft-jpeg", - "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=c6f4f5115e6d7e5a53180f297c7cda8c5c4cb3c9)", + "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=42abc84c82cd573e2fb0277298caffecb7bee905)", "crc32fast", "exr", "flate2", @@ -1291,7 +1291,7 @@ dependencies = [ [[package]] name = "craft-jpeg" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=c6f4f5115e6d7e5a53180f297c7cda8c5c4cb3c9#c6f4f5115e6d7e5a53180f297c7cda8c5c4cb3c9" +source = "git+https://github.com/storytold/craft-libs?rev=42abc84c82cd573e2fb0277298caffecb7bee905#42abc84c82cd573e2fb0277298caffecb7bee905" dependencies = [ "thiserror 2.0.21", ] @@ -1309,11 +1309,11 @@ dependencies = [ [[package]] name = "craft-metadata" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=c6f4f5115e6d7e5a53180f297c7cda8c5c4cb3c9#c6f4f5115e6d7e5a53180f297c7cda8c5c4cb3c9" +source = "git+https://github.com/storytold/craft-libs?rev=42abc84c82cd573e2fb0277298caffecb7bee905#42abc84c82cd573e2fb0277298caffecb7bee905" dependencies = [ "brotli-decompressor 6.0.1", "chrono", - "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=c6f4f5115e6d7e5a53180f297c7cda8c5c4cb3c9)", + "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=42abc84c82cd573e2fb0277298caffecb7bee905)", "quick-xml 0.41.0", "serde", ] @@ -1362,7 +1362,7 @@ dependencies = [ [[package]] name = "craft-tiff" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=c6f4f5115e6d7e5a53180f297c7cda8c5c4cb3c9#c6f4f5115e6d7e5a53180f297c7cda8c5c4cb3c9" +source = "git+https://github.com/storytold/craft-libs?rev=42abc84c82cd573e2fb0277298caffecb7bee905#42abc84c82cd573e2fb0277298caffecb7bee905" dependencies = [ "serde", "thiserror 2.0.21", @@ -3865,6 +3865,7 @@ dependencies = [ "craft-heif", "craft-image-codecs", "craft-jxl", + "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=42abc84c82cd573e2fb0277298caffecb7bee905)", "craft-psd", "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18)", "dhat", @@ -4100,7 +4101,7 @@ version = "0.21.1" dependencies = [ "chrono", "craft-heif", - "craft-metadata 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=42abc84c82cd573e2fb0277298caffecb7bee905)", "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 ac0913663f..82af4ae968 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,8 +18,8 @@ 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-image-codecs = { git = "https://github.com/storytold/craft-libs", rev = "c6f4f5115e6d7e5a53180f297c7cda8c5c4cb3c9" } +craft-metadata = { git = "https://github.com/storytold/craft-libs", rev = "42abc84c82cd573e2fb0277298caffecb7bee905" } +craft-image-codecs = { git = "https://github.com/storytold/craft-libs", rev = "42abc84c82cd573e2fb0277298caffecb7bee905" } craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "f0f4758c01581d79577b9bf5046c06f4e77b1f18" } # craft-update: app-specific pretend versions apply to startup and manual checks. craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "6e03f65bf45181db77ba6229716e6624db9eb25b", features = ["egui"] } 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/exif.rs b/crates/codecs/src/exif.rs index 2e1d29989b..b3e45fef68 100644 --- a/crates/codecs/src/exif.rs +++ b/crates/codecs/src/exif.rs @@ -80,6 +80,10 @@ impl<'a> Tiff<'a> { } } +pub use craft_metadata::compat_orientation::minimal_exif; +pub(crate) use craft_metadata::compat_orientation::summarize; + +#[cfg(test)] /// What the decoder cares about from an EXIF (TIFF-structured) blob. #[derive(Clone, Debug, Default, PartialEq)] pub(crate) struct ExifSummary { @@ -90,7 +94,8 @@ pub(crate) struct ExifSummary { pub adobe_rgb_hint: bool, } -pub(crate) fn summarize(blob: &[u8]) -> ExifSummary { +#[cfg(test)] +pub(crate) fn legacy_reference(blob: &[u8]) -> ExifSummary { let mut s = ExifSummary::default(); let Some(t) = Tiff::new(blob) else { return s }; let Some(ifd0) = t.first_ifd() else { return s }; @@ -130,23 +135,6 @@ pub(crate) fn summarize(blob: &[u8]) -> ExifSummary { s } -/// Build a tiny EXIF blob (little-endian TIFF) with just an orientation tag. Used by tests and by -/// callers that need to stamp orientation on export when no source EXIF exists. -pub fn minimal_exif(orientation: u16) -> Vec { - let mut v = Vec::with_capacity(26); - v.extend_from_slice(b"II"); - v.extend_from_slice(&42u16.to_le_bytes()); - v.extend_from_slice(&8u32.to_le_bytes()); - v.extend_from_slice(&1u16.to_le_bytes()); - v.extend_from_slice(&0x0112u16.to_le_bytes()); - v.extend_from_slice(&3u16.to_le_bytes()); - v.extend_from_slice(&1u32.to_le_bytes()); - v.extend_from_slice(&orientation.to_le_bytes()); - v.extend_from_slice(&[0, 0]); - v.extend_from_slice(&0u32.to_le_bytes()); - v -} - #[cfg(test)] mod tests { use super::*; @@ -160,7 +148,7 @@ mod tests { #[test] fn garbage_ok() { - assert_eq!(summarize(b"II*\0\xff\xff\xff\xff"), ExifSummary::default()); - assert_eq!(summarize(&[]), ExifSummary::default()); + assert_eq!(legacy_reference(b"II*\0\xff\xff\xff\xff"), ExifSummary::default()); + assert_eq!(legacy_reference(&[]), ExifSummary::default()); } } diff --git a/crates/codecs/src/png_codec.rs b/crates/codecs/src/png_codec.rs index 8f81527782..a946516584 100644 --- a/crates/codecs/src/png_codec.rs +++ b/crates/codecs/src/png_codec.rs @@ -121,7 +121,7 @@ mod tests { let mut png = base.clone(); let iend = png.len() - 12; png.splice(iend..iend, png_chunk(*b"eXIf", &data)); - assert_eq!(super::header(&png).unwrap().2, crate::exif::summarize(&data).orientation.unwrap_or(1), "at {at}, value {value}"); + assert_eq!(super::header(&png).unwrap().2, crate::exif::legacy_reference(&data).orientation.unwrap_or(1), "at {at}, value {value}"); } } } From 697e72c74b4126ae01f7195e7213bf81c1c6af96 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 17:22:22 +0000 Subject: [PATCH 05/14] Compare legacy EXIF summary behavior --- crates/codecs/src/png_codec.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/crates/codecs/src/png_codec.rs b/crates/codecs/src/png_codec.rs index a946516584..6fe9964c62 100644 --- a/crates/codecs/src/png_codec.rs +++ b/crates/codecs/src/png_codec.rs @@ -106,9 +106,6 @@ fn rgb_to_xyz_d50_checked(space: &RgbSpace) -> Option { mod tests { use crate::DecodeOptions; - /// A compressed text chunk is expanded by `png` through our own cap: an XMP document - /// bigger than it is dropped, not inflated. Compressing an 8 MiB string is a few - /// kilobytes — the reverse of what the unbounded `get_text()` path allowed. #[test] fn exif_orientation_mutation_parity() { let image = craft_image_codecs::Image::from_u8(1, 1, craft_image_codecs::ChannelLayout::Gray, vec![0]).unwrap(); @@ -121,11 +118,17 @@ mod tests { let mut png = base.clone(); let iend = png.len() - 12; png.splice(iend..iend, png_chunk(*b"eXIf", &data)); - assert_eq!(super::header(&png).unwrap().2, crate::exif::legacy_reference(&data).orientation.unwrap_or(1), "at {at}, value {value}"); + let old = crate::exif::legacy_reference(&data); + let shared = crate::exif::summarize(&data); + assert_eq!((shared.orientation, shared.thumbnail, shared.adobe_rgb_hint), (old.orientation, old.thumbnail, old.adobe_rgb_hint)); + assert_eq!(super::header(&png).unwrap().2, old.orientation.unwrap_or(1), "at {at}, value {value}"); } } } + /// A compressed text chunk is expanded by `png` through our own cap: an XMP document + /// bigger than it is dropped, not inflated. Compressing an 8 MiB string is a few + /// kilobytes — the reverse of what the unbounded `get_text()` path allowed. #[test] fn compressed_xmp_over_the_cap_is_dropped() { let out = png_with_compressed_xmp(&"x".repeat(8 << 20)); From df8ec2e3660c726ae8f96d8648685f9fcf4baf40 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 17:48:11 +0000 Subject: [PATCH 06/14] Keep metadata and TIFF dependencies on same revision --- Cargo.lock | 45 ++++++++++++--------------------------------- Cargo.toml | 4 ++-- 2 files changed, 14 insertions(+), 35 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8e54612419..5d29ca54f2 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=42abc84c82cd573e2fb0277298caffecb7bee905#42abc84c82cd573e2fb0277298caffecb7bee905" dependencies = [ "thiserror 2.0.21", ] @@ -1269,7 +1269,7 @@ version = "0.1.0" source = "git+https://github.com/storytold/craft-libs?rev=42abc84c82cd573e2fb0277298caffecb7bee905#42abc84c82cd573e2fb0277298caffecb7bee905" dependencies = [ "craft-jpeg", - "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=42abc84c82cd573e2fb0277298caffecb7bee905)", + "craft-metadata", "crc32fast", "exr", "flate2", @@ -1313,19 +1313,7 @@ source = "git+https://github.com/storytold/craft-libs?rev=42abc84c82cd573e2fb027 dependencies = [ "brotli-decompressor 6.0.1", "chrono", - "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=42abc84c82cd573e2fb0277298caffecb7bee905)", - "quick-xml 0.41.0", - "serde", -] - -[[package]] -name = "craft-metadata" -version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18#f0f4758c01581d79577b9bf5046c06f4e77b1f18" -dependencies = [ - "brotli-decompressor 6.0.1", - "chrono", - "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18)", + "craft-tiff", "quick-xml 0.41.0", "serde", ] @@ -1344,12 +1332,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=42abc84c82cd573e2fb0277298caffecb7bee905#42abc84c82cd573e2fb0277298caffecb7bee905" 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", + "craft-tiff", "jxl-oxide", "miniz_oxide 0.9.1", "rayon", @@ -1368,15 +1356,6 @@ dependencies = [ "thiserror 2.0.21", ] -[[package]] -name = "craft-tiff" -version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18#f0f4758c01581d79577b9bf5046c06f4e77b1f18" -dependencies = [ - "serde", - "thiserror 2.0.21", -] - [[package]] name = "craft-ui" version = "0.1.0" @@ -3865,9 +3844,9 @@ dependencies = [ "craft-heif", "craft-image-codecs", "craft-jxl", - "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=42abc84c82cd573e2fb0277298caffecb7bee905)", + "craft-metadata", "craft-psd", - "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18)", + "craft-tiff", "dhat", "jxl-oxide", "lightcraft-color", @@ -3944,7 +3923,7 @@ dependencies = [ "chrono", "craft-docpath", "craft-heif", - "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18)", + "craft-tiff", "crc32fast", "fs4", "harfrust 0.13.3", @@ -4101,9 +4080,9 @@ version = "0.21.1" dependencies = [ "chrono", "craft-heif", - "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=42abc84c82cd573e2fb0277298caffecb7bee905)", + "craft-metadata", "craft-psd", - "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18)", + "craft-tiff", "lightcraft-geom", "proptest", "serde", @@ -4158,7 +4137,7 @@ dependencies = [ "chrono", "craft-image-codecs", "craft-raw", - "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18)", + "craft-tiff", "dhat", "lightcraft-color", "lightcraft-geom", diff --git a/Cargo.toml b/Cargo.toml index 82af4ae968..1469b25fd9 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 = "42abc84c82cd573e2fb0277298caffecb7bee905" } # 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 = "42abc84c82cd573e2fb0277298caffecb7bee905" } lightcraft-raw = { path = "crates/raw" } lightcraft-codecs = { path = "crates/codecs" } lightcraft-meta = { path = "crates/meta" } From 8c013aec83857dd362fe83c22f42af3fb7f8fc87 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 18:54:10 +0000 Subject: [PATCH 07/14] Keep RAW fixtures valid under shared container and strip bounds --- crates/raw/tests/it/cr3_variants.rs | 6 +++--- crates/raw/tests/it/crx_properties.rs | 5 ++--- crates/raw/tests/it/dng.rs | 3 ++- crates/raw/tests/it/robust.rs | 5 ++--- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/crates/raw/tests/it/cr3_variants.rs b/crates/raw/tests/it/cr3_variants.rs index 54d7f8d9f2..fb6628561d 100644 --- a/crates/raw/tests/it/cr3_variants.rs +++ b/crates/raw/tests/it/cr3_variants.rs @@ -105,10 +105,10 @@ fn cr3_file(coding: &[u8], sample: &[u8]) -> Vec { 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)); - let offset = file.len(); - file.extend_from_slice(sample); - let at = file.len() - sample.len() - 8; // the co64 offset field ends the moov + let at = file.len() - 8; // the co64 offset field ends the moov + let offset = file.len() + 8; // samples belong to the mdat payload, after its header file[at..at + 8].copy_from_slice(&u64::try_from(offset).unwrap().to_be_bytes()); + file.extend(box_bytes(b"mdat", sample)); file } diff --git a/crates/raw/tests/it/crx_properties.rs b/crates/raw/tests/it/crx_properties.rs index 30ff2dd195..215f2c3405 100644 --- a/crates/raw/tests/it/crx_properties.rs +++ b/crates/raw/tests/it/crx_properties.rs @@ -410,11 +410,10 @@ fn cr3_file(entry: &[u8], sample: &[u8]) -> Vec { // The track length does not depend on the offset value (always a 64-bit field), so it can be // measured with a placeholder before the real offset is known. let track_len = track_box(entry, 0, sample.len() as u32).len(); - let offset = (ftyp.len() + 8 + track_len + 7) & !7; + let offset = ftyp.len() + 8 + track_len + 8; // moov and mdat headers let mut file = ftyp; file.extend(box_bytes(b"moov", &track_box(entry, offset as u64, sample.len() as u32))); - file.resize(offset, 0); - file.extend_from_slice(sample); + file.extend(box_bytes(b"mdat", sample)); file } diff --git a/crates/raw/tests/it/dng.rs b/crates/raw/tests/it/dng.rs index 79b1a15d40..7e6685bdb7 100644 --- a/crates/raw/tests/it/dng.rs +++ b/crates/raw/tests/it/dng.rs @@ -1016,7 +1016,8 @@ fn malformed_semantic_masks_are_skipped() { assert_eq!(decode(&bytes).unwrap().cpp, 3); let masks = lightcraft_raw::semantic_masks(&bytes); let names: Vec<&str> = masks.iter().map(|m| m.name.as_str()).collect(); - assert_eq!(names, ["short strip", "sub area too small"]); + // Truncated strip pixels are rejected by the shared reader instead of zero-filled. + assert_eq!(names, ["sub area too small"]); assert!(masks.iter().all(|m| m.sub_area.is_none()), "sub areas the mask doesn't fit are ignored"); for m in &masks { let d = m.developed(Rect::new(0, 0, 8, 6), Rect::new(0, 0, 8, 6)).unwrap(); diff --git a/crates/raw/tests/it/robust.rs b/crates/raw/tests/it/robust.rs index 3cd54e47e9..1d864da1df 100644 --- a/crates/raw/tests/it/robust.rs +++ b/crates/raw/tests/it/robust.rs @@ -231,11 +231,10 @@ mod cr3 { let entry = box_bytes(b"CRAW", &craw); let ftyp = box_bytes(b"ftyp", b"crx \0\0\0\x01crx isom"); let track_len = track(&entry, 0, sample.len() as u32).len(); - let offset = (ftyp.len() + 8 + track_len + 7) & !7; + let offset = ftyp.len() + 8 + track_len + 8; // moov and mdat headers let mut out = ftyp; out.extend(box_bytes(b"moov", &track(&entry, offset as u64, sample.len() as u32))); - out.resize(offset, 0); - out.extend_from_slice(sample); + out.extend(box_bytes(b"mdat", sample)); out } From b08bbae18e50ee51ef1d85295a0f6b345517e9d3 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 19:12:44 +0000 Subject: [PATCH 08/14] Use coverage settle budget for asynchronous UI checks --- crates/ui-egui/src/headless/tests.rs | 2 +- crates/ui-egui/src/tests/activity.rs | 2 +- crates/ui-egui/src/tests/preview_limit.rs | 6 +++--- crates/ui-egui/src/tests/slideshow.rs | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/ui-egui/src/headless/tests.rs b/crates/ui-egui/src/headless/tests.rs index eb05be0c4c..157f389334 100644 --- a/crates/ui-egui/src/headless/tests.rs +++ b/crates/ui-egui/src/headless/tests.rs @@ -2343,7 +2343,7 @@ fn preview_only_raw_shows_badge_and_notices() { // …which re-reads the file and says what came of it (a demo photo has none to re-read) let r = h.request("ui.clickWidget", json!({"id": "button:reloadPreviewOnly:info"}), t); assert_eq!(r["ok"], true, "{r}"); - h.settle(SETTLE); + // Read the timed toast before settling advances the simulated clock past its expiry. assert_eq!(h.app.ui.toast.clone().map(|x| x.0).as_deref(), Some("This raw variant still can't be decoded")); // a regular photo: no notice h.request("engine.execute", json!({"command": "library.select", "params": {"ids": [other.0]}}), t); diff --git a/crates/ui-egui/src/tests/activity.rs b/crates/ui-egui/src/tests/activity.rs index b353405ffc..f8f32607a2 100644 --- a/crates/ui-egui/src/tests/activity.rs +++ b/crates/ui-egui/src/tests/activity.rs @@ -509,7 +509,7 @@ fn batch_merge_runs_each_set_in_turn() { let rows = h.app.session.activity.list(); assert_eq!((rows.len(), rows.first().map(|r| r.kind)), (1, Some("merge"))); // the first merge finishes and the second starts by itself - assert!(h.step_until(T, |h| h.app.merge.batch.len() == 1 && h.app.merge.final_task.is_some())); + assert!(h.step_until(super::ui_settle_timeout(), |h| h.app.merge.batch.len() == 1 && h.app.merge.final_task.is_some())); assert_eq!(h.app.session.catalog.len(), 10); // cancelling the second drops the third let rows = h.app.session.activity.list(); diff --git a/crates/ui-egui/src/tests/preview_limit.rs b/crates/ui-egui/src/tests/preview_limit.rs index 5d1c1b7d0e..8d19a71734 100644 --- a/crates/ui-egui/src/tests/preview_limit.rs +++ b/crates/ui-egui/src/tests/preview_limit.rs @@ -162,7 +162,7 @@ mod in_the_loupe { let mut h = Headless::new(app, size, 1.0); let r = h.request("ui.set", json!({"view": "detail", "right": "none", "filmstrip": false}), T); assert_eq!(r["ok"], true, "{r}"); - h.settle(SETTLE); + h.settle(super::super::ui_settle_timeout()); let native = { let id = h.app.session.active().expect("a photo is open"); let p = h.app.session.catalog.photo(id).expect("it is in the catalog"); @@ -848,7 +848,7 @@ mod in_the_loupe { #[test] fn pinch_display_fit_does_not_follow_the_old_photo() { let (mut h, _) = demo_detail_in([1400.0, 900.0]); - assert!(h.settle(SETTLE)); + assert!(h.settle(super::super::ui_settle_timeout())); let old = h.app.session.active().unwrap(); let next = h.app.session.visible_cloned().into_iter().find(|id| *id != old).unwrap(); let initial_fit = drawn_fit(&h); @@ -874,7 +874,7 @@ mod in_the_loupe { fn pinch_display_fit_is_shared_with_a_hover_during_the_hold() { let (mut h, _) = demo_detail_in([1400.0, 900.0]); assert_eq!(h.request("engine.execute", json!({"command": "panel.profiles"}), T)["ok"], true); - assert!(h.settle(SETTLE)); + assert!(h.settle(super::super::ui_settle_timeout())); let initial_fit = drawn_fit(&h); let work = std::rc::Rc::new(std::cell::RefCell::new(PinchWork::default())); h.app.renderer.set_offload(Box::new(PinchOffload(work.clone()))); diff --git a/crates/ui-egui/src/tests/slideshow.rs b/crates/ui-egui/src/tests/slideshow.rs index 4e230fe7a5..1659005ab7 100644 --- a/crates/ui-egui/src/tests/slideshow.rs +++ b/crates/ui-egui/src/tests/slideshow.rs @@ -457,7 +457,7 @@ fn a_photo_deleted_while_it_plays_does_not_stall_the_slideshow() { run(&mut h, "photo.delete", json!({"ids": [next.0]})); run(&mut h, "photo.deletePermanently", json!({"ids": [next.0]})); assert!(h.app.session.catalog.photo(next).is_none()); - assert!(h.step_until(SETTLE, |h| h.app.ui.slideshow.as_ref().is_some_and(|r| r.play.position().0 >= 3)), "it plays on"); + assert!(h.step_until(super::ui_settle_timeout(), |h| h.app.ui.slideshow.as_ref().is_some_and(|r| r.play.position().0 >= 3)), "it plays on"); assert!(photos.len() > 3); h.settle(SETTLE); } @@ -630,7 +630,7 @@ fn settings_shows_the_slide_layout_and_a_live_preview() { assert!(has(&h, w), "{w}"); } // the preview is the composed slide, rendered off the UI thread - assert!(h.step_until(SETTLE, |h| h.app.renderer.textures.get(&Slot::SlidePreview).is_some_and(|t| t.photo == first))); + assert!(h.step_until(super::ui_settle_timeout(), |h| h.app.renderer.textures.get(&Slot::SlidePreview).is_some_and(|t| t.photo == first))); // a checkbox goes through slideshow.layout, and its controls appear (scrolled into view) reveal(&mut h, "check:settings.slideshowShadow"); let r = h.request("ui.clickWidget", json!({"id": "check:settings.slideshowShadow"}), T); @@ -641,7 +641,7 @@ fn settings_shows_the_slide_layout_and_a_live_preview() { // a changed layout renders the preview again (once it has settled) let before = h.app.renderer.textures.get(&Slot::SlidePreview).map(|t| t.key); run(&mut h, "slideshow.layout", json!({"margins": 0.2, "backdropColor": "#00ff00"})); - assert!(h.step_until(SETTLE, |h| h.app.renderer.textures.get(&Slot::SlidePreview).map(|t| t.key) != before)); + assert!(h.step_until(super::ui_settle_timeout(), |h| h.app.renderer.textures.get(&Slot::SlidePreview).map(|t| t.key) != before)); h.step(); // (the preview is pinned above the page: in view already) reveal(&mut h, "slideshow:preview"); From 2ed45956638ccb24fe576fca6d0525623f02ea6e Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 17:26:54 -0500 Subject: [PATCH 09/14] 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 fb6628561d..1da91d41cf 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 215f2c3405..5f99837394 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 1d864da1df..41a4ef302e 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 310b26503decad7fdea035cde7d108464e048757 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 18:03:13 -0500 Subject: [PATCH 10/14] codecs: delegate ICC embedding normalization to craft-cms --- Cargo.lock | 2 +- Cargo.toml | 2 +- crates/codecs/src/icc.rs | 53 +--------------------------------------- 3 files changed, 3 insertions(+), 54 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b322552f35..762ed87290 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1190,7 +1190,7 @@ dependencies = [ [[package]] name = "craft-cms" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=94777dcf7f8962476e96b049d08d22e25b9330c2#94777dcf7f8962476e96b049d08d22e25b9330c2" +source = "git+https://github.com/storytold/craft-libs?rev=7306195df57e7483a58600fa216bac9319030d86#7306195df57e7483a58600fa216bac9319030d86" dependencies = [ "md-5", "rayon", diff --git a/Cargo.toml b/Cargo.toml index ec2701598a..8e66939143 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ craft-ui = { git = "https://github.com/storytold/craft-libs", rev = "c5a1cbfb5f9 craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "c5a1cbfb5f9049f9270955caffb5bee5997aebf7" } # Canon CRW decoder shared with the other Craft apps craft-crw = { git = "https://github.com/storytold/craft-libs", rev = "94777dcf7f8962476e96b049d08d22e25b9330c2" } -craft-cms = { git = "https://github.com/storytold/craft-libs", rev = "94777dcf7f8962476e96b049d08d22e25b9330c2" } +craft-cms = { git = "https://github.com/storytold/craft-libs", rev = "7306195df57e7483a58600fa216bac9319030d86" } craft-mime = { git = "https://github.com/storytold/craft-libs", rev = "f0f4758c01581d79577b9bf5046c06f4e77b1f18", version = "0.1.0" } 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"] } diff --git a/crates/codecs/src/icc.rs b/crates/codecs/src/icc.rs index 2dcbe36deb..111f78be58 100644 --- a/crates/codecs/src/icc.rs +++ b/crates/codecs/src/icc.rs @@ -132,58 +132,7 @@ pub fn write_matrix_trc(space: &RgbSpace, trc: &Trc) -> Vec { }; p.copyright = "No copyright, use freely".to_string(); let encoded = p.with_encoded_bytes(); - align_tags(&fixed_date(encoded.to_bytes().to_vec())) -} - -/// Zero the header's creation date/time (ICC.1 §7.2.8, bytes 24..36) so a profile's bytes depend -/// only on its colour space and curve. `moxcms` stamps the wall clock there on every `encode` -/// (ignoring `ColorProfile::creation_date_time`), which made two exports of one photo differ in -/// the embedded profile and nowhere else, so output hashes could not be compared (#180). Readers -/// do not interpret the field; all zeros is the conventional "unspecified" value. -fn fixed_date(mut b: Vec) -> Vec { - if let Some(date) = b.get_mut(24..36) { - date.fill(0); - } - b -} - -/// Re-lay a profile's tag data on 4-byte boundaries (ICC.1 §7.3.1). The encoder packs tags back to -/// back, so a tag of odd length (e.g. a `mluc` description with an odd number of characters) -/// misaligns every following tag — which some readers (macOS ImageIO for PNG `iCCP`) reject. -fn align_tags(b: &[u8]) -> Vec { - let be = |i: usize| b.get(i..i + 4).map(|s| u32::from_be_bytes([s[0], s[1], s[2], s[3]]) as usize); - let Some(n) = be(128) else { return b.to_vec() }; - let table_end = 132 + 12 * n; - let tags: Option> = (0..n).map(|t| Some((be(132 + 12 * t + 4)?, be(132 + 12 * t + 8)?))).collect(); - let Some(tags) = tags.filter(|t| table_end <= b.len() && t.iter().all(|&(o, l)| o >= table_end && o + l <= b.len())) else { - return b.to_vec(); - }; - let mut out = b[..table_end].to_vec(); - let mut placed: Vec<((usize, usize), usize)> = Vec::new(); - for (t, &(off, len)) in tags.iter().enumerate() { - let new_off = match placed.iter().find(|(k, _)| *k == (off, len)) { - // tags sharing data keep sharing it - Some(&(_, o)) => o, - None => { - while !out.len().is_multiple_of(4) { - out.push(0); - } - let o = out.len(); - out.extend_from_slice(&b[off..off + len]); - placed.push(((off, len), o)); - o - } - }; - out[132 + 12 * t + 4..132 + 12 * t + 8].copy_from_slice(&(new_off as u32).to_be_bytes()); - } - while !out.len().is_multiple_of(4) { - out.push(0); - } - let size = out.len() as u32; - out[0..4].copy_from_slice(&size.to_be_bytes()); - // the profile ID (MD5) would no longer match: clear it (= "not computed") - out[84..100].fill(0); - out + craft_cms::normalize_for_embedding(encoded.to_bytes().to_vec()) } /// A profile for one of the well-known spaces with its standard curve. From 45f887995beb24e58b356e33e6b321e07a120a21 Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Mon, 16 Nov 2026 08:32:38 +0100 Subject: [PATCH 11/14] codecs: test PNG header and decode agree on conflicting Orientation entries --- crates/codecs/src/png_codec.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/crates/codecs/src/png_codec.rs b/crates/codecs/src/png_codec.rs index 6fe9964c62..fa962002d7 100644 --- a/crates/codecs/src/png_codec.rs +++ b/crates/codecs/src/png_codec.rs @@ -106,6 +106,30 @@ fn rgb_to_xyz_d50_checked(space: &RgbSpace) -> Option { mod tests { use crate::DecodeOptions; + /// An IFD0 with two Orientation entries (1, then 6): `read_header` and `decode` read it with + /// the same reader, so they agree on the orientation. + #[test] + fn header_and_decode_agree_on_conflicting_orientation_entries() { + let image = craft_image_codecs::Image::from_u8(2, 3, craft_image_codecs::ChannelLayout::Gray, vec![0; 6]).unwrap(); + let base = craft_image_codecs::encode(&image, craft_image_codecs::Format::Png, &craft_image_codecs::EncodeOptions::default()).unwrap(); + let mut exif = b"II*\0\x08\0\0\0\x02\0".to_vec(); + for value in [1u16, 6] { + exif.extend_from_slice(&0x0112u16.to_le_bytes()); + exif.extend_from_slice(&3u16.to_le_bytes()); + exif.extend_from_slice(&1u32.to_le_bytes()); + exif.extend_from_slice(&value.to_le_bytes()); + exif.extend_from_slice(&[0, 0]); + } + exif.extend_from_slice(&0u32.to_le_bytes()); + let mut png = base.clone(); + let iend = png.len() - 12; + png.splice(iend..iend, png_chunk(*b"eXIf", &exif)); + let header = crate::read_header(&png).unwrap(); + let decoded = crate::decode(&png, DecodeOptions::default()).unwrap(); + assert_eq!((header.width, header.height), (2, 3)); + assert_eq!(header.orientation, decoded.orientation); + } + #[test] fn exif_orientation_mutation_parity() { let image = craft_image_codecs::Image::from_u8(1, 1, craft_image_codecs::ChannelLayout::Gray, vec![0]).unwrap(); From fd1faf45bbfda7bea0c134f48f048c6301690a4d Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Mon, 16 Nov 2026 04:51:11 -0500 Subject: [PATCH 12/14] Use established async completion budgets for remaining UI waits --- crates/ui-egui/src/tests/activity.rs | 2 +- crates/ui-egui/src/tests/preview_limit.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/tests/activity.rs b/crates/ui-egui/src/tests/activity.rs index f8f32607a2..db6320a4b1 100644 --- a/crates/ui-egui/src/tests/activity.rs +++ b/crates/ui-egui/src/tests/activity.rs @@ -464,7 +464,7 @@ fn merge_dialog_retries_a_failed_preview_when_it_opens_again() { h.app.merge.preview.is_some() || h.app.merge.preview_task.is_some() || h.app.merge.error.is_some(), "the dialog shows a preview, one being made, or why not" ); - assert!(h.step_until(T, |h| h.app.merge.preview_task.is_none())); + assert!(h.step_until(super::ui_settle_timeout(), |h| h.app.merge.preview_task.is_none())); assert!(h.app.merge.preview.is_some(), "{:?}", h.app.merge.error); h.app.ui.dialog = None; h.step(); diff --git a/crates/ui-egui/src/tests/preview_limit.rs b/crates/ui-egui/src/tests/preview_limit.rs index 8d19a71734..248ce781cc 100644 --- a/crates/ui-egui/src/tests/preview_limit.rs +++ b/crates/ui-egui/src/tests/preview_limit.rs @@ -811,7 +811,7 @@ mod in_the_loupe { fn pinch_display_fit_refreshes_main_and_before_after_a_short_pinch() { let (mut h, _) = demo_detail_in([1400.0, 900.0]); h.app.ui.before_after = crate::state::BeforeAfter::SideBySide; - assert!(h.settle(SETTLE)); + assert!(h.settle(super::super::ui_settle_timeout())); let slots = [Slot::Main, Slot::Before]; let keys = slots.map(|slot| h.app.renderer.wanted(slot).unwrap()); let initial_fit = drawn_fit(&h); From 3a616261e3fa64d4676eda97a7129ee661c0b982 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Mon, 16 Nov 2026 05:13:38 -0500 Subject: [PATCH 13/14] Allow instrumented preview decoders to finish before reporting failure --- crates/ui-egui/src/tests/activity.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ui-egui/src/tests/activity.rs b/crates/ui-egui/src/tests/activity.rs index db6320a4b1..bdeaccf4e9 100644 --- a/crates/ui-egui/src/tests/activity.rs +++ b/crates/ui-egui/src/tests/activity.rs @@ -452,7 +452,7 @@ fn merge_dialog_retries_a_failed_preview_when_it_opens_again() { std::fs::rename(&file, &away).unwrap(); crate::merge::open(&mut h.app, "merge.panorama").unwrap(); h.step(); - assert!(h.step_until(T, |h| h.app.merge.preview_task.is_none())); + assert!(h.step_until(super::ui_settle_timeout(), |h| h.app.merge.preview_task.is_none())); assert!(h.app.merge.error.is_some(), "the preview failed"); h.app.ui.dialog = None; h.step(); From b3188d182a17d50a8edaf0cbf5db7e82d88e737e Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Mon, 16 Nov 2026 06:26:52 -0500 Subject: [PATCH 14/14] docs: prefer shared Craft libraries for reusable features --- AGENTS.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/AGENTS.md b/AGENTS.md index 8d0ca31a60..76c593c1d8 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -229,3 +229,7 @@ evaluates it (`.github/workflows/nix.yml`), so the build may lag behind the work - Don't add or change CI in a feature or fix PR. If the existing workflows can't build or test a change, link an existing craft-common-actions issue or PR, or open a new issue, or a PR only for a small fix that is safe for every app and does not increase CI time. - `ci.yml` is the Linux gate, on every pull request. `ci-windows.yml` adds a Windows leg (clippy and tests of the crates with `cfg(windows)` code) when a pull request changes the paths it lists; add the `full-ci` label to run it on any other pull request. When you add `cfg(windows)` code in a new file, add the file to its `paths` in a CI PR. - Some workflow files here still run their own jobs. Don't add to them. Moving a job into craft-common-actions is its own task, never part of another PR, and the job stays here until a shared workflow runs it. + +## Shared libraries + +Before adding or changing file-format, codec, protocol, or reusable UI code, check `storytold/craft-libs` and its open PRs first; reuse or extend the shared library rather than duplicating it locally, keep app-specific policy and model mapping in the app, and preserve behavior, security/resource limits, attribution, and regression coverage during cutovers.