From 6b0e7c62e865c624368eb452a993a0c97ecff9cd Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 16:15:50 +0000 Subject: [PATCH 1/3] Use shared TIFF header validation --- Cargo.lock | 55 +++++++++++--- Cargo.toml | 2 +- NOTICE | 124 ++++++++++++++++++++++++++++++++ crates/codecs/src/tiff_codec.rs | 31 ++------ 4 files changed, 174 insertions(+), 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 04c07b04f1..439286b284 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1266,13 +1266,16 @@ 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=fb6cb780061c6744ed6886e7dd1a80ccf449e655#fb6cb780061c6744ed6886e7dd1a80ccf449e655" dependencies = [ "craft-jpeg", - "craft-metadata", + "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=fb6cb780061c6744ed6886e7dd1a80ccf449e655)", + "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=fb6cb780061c6744ed6886e7dd1a80ccf449e655)", + "crc32fast", "exr", "flate2", "half", + "hayro-jpeg2000", "image", "image-webp", "jpeg-encoder", @@ -1289,7 +1292,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=fb6cb780061c6744ed6886e7dd1a80ccf449e655#fb6cb780061c6744ed6886e7dd1a80ccf449e655" dependencies = [ "thiserror 2.0.21", ] @@ -1311,7 +1314,19 @@ 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", +] + +[[package]] +name = "craft-metadata" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=fb6cb780061c6744ed6886e7dd1a80ccf449e655#fb6cb780061c6744ed6886e7dd1a80ccf449e655" +dependencies = [ + "brotli-decompressor 6.0.1", + "chrono", + "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=fb6cb780061c6744ed6886e7dd1a80ccf449e655)", "quick-xml 0.41.0", "serde", ] @@ -1334,8 +1349,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", @@ -1354,6 +1369,15 @@ dependencies = [ "thiserror 2.0.21", ] +[[package]] +name = "craft-tiff" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=fb6cb780061c6744ed6886e7dd1a80ccf449e655#fb6cb780061c6744ed6886e7dd1a80ccf449e655" +dependencies = [ + "serde", + "thiserror 2.0.21", +] + [[package]] name = "craft-ui" version = "0.1.0" @@ -3033,6 +3057,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 +3867,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 +3944,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 +4101,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 +4158,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..8c48d8d6d6 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 = "fb6cb780061c6744ed6886e7dd1a80ccf449e655" } 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/tiff_codec.rs b/crates/codecs/src/tiff_codec.rs index 1ad9c802f8..955756ca66 100644 --- a/crates/codecs/src/tiff_codec.rs +++ b/crates/codecs/src/tiff_codec.rs @@ -68,30 +68,9 @@ pub(crate) fn decode(bytes: &[u8], opts: &DecodeOptions) -> Result { /// as a decode would refuse it: a layout or compression we can't decode, or strips/tiles that /// start past the end of the file (truncated). The compressed data itself is not checked. pub(crate) fn header(bytes: &[u8]) -> Result<(u32, u32, u16)> { - let (tiff, complete) = craft_tiff::Tiff::parse_with_status(bytes, &Default::default()).map_err(err)?; - if !complete { - return Err(err("truncated TIFF")); - } - let ifd = tiff.ifds.first().ok_or_else(|| err("no IFD"))?; - let info = ifd.image().map_err(err)?; - check_size(F, info.width as u64, info.height as u64, &DecodeOptions::default())?; - let bits = info.bits_per_sample.first().copied().unwrap_or(1); - if bits < 8 && info.planar == 2 && info.samples_per_pixel > 1 { - return Err(Error::Unsupported(F, "planar TIFF with samples narrower than a byte")); - } - if !(matches!(info.photometric, 0 | 1 | 2 | 3 | 5) || info.photometric == 6 && info.compression == 7) { - return Err(Error::Unsupported(F, "colour type")); - } - // what `craft-image-codecs`'s TIFF decoder decompresses: none, CCITT G4, LZW, JPEG, Deflate, PackBits - if !matches!(info.compression, 1 | 4 | 5 | 7 | 8 | 32773 | 32946) { - return Err(Error::Unsupported(F, "compression method")); - } - let len = bytes.len() as u64; - if info.offsets.is_empty() - || info.offsets.iter().zip(&info.byte_counts).any(|(&o, &c)| c > 0 && (o >= len || (info.compression == 1 && o.saturating_add(c) > len))) - { - return Err(err("truncated: image data past the end of the file")); - } - let orientation = ifd.u16(craft_tiff::tags::ORIENTATION).filter(|o| (1..=8).contains(o)).unwrap_or(1); - Ok((info.width, info.height, orientation)) + craft_image_codecs::tiff_probe::header(bytes, DecodeOptions::default().max_pixels).map_err(|error| match error { + craft_image_codecs::tiff_probe::Error::TooLarge { width, height } => Error::TooLarge(u64::from(width), u64::from(height)), + craft_image_codecs::tiff_probe::Error::Unsupported(reason) => Error::Unsupported(F, reason), + craft_image_codecs::tiff_probe::Error::Malformed(message) => err(message), + }) } From 3d524ceef7140557f065c1352bde17a525f48116 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 16:17:55 +0000 Subject: [PATCH 2/3] Share TIFF decode preflight inspection --- Cargo.lock | 20 ++++++++++---------- Cargo.toml | 2 +- crates/codecs/src/tiff_codec.rs | 22 ++++++++++------------ 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 439286b284..e7b49767c2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1266,11 +1266,11 @@ dependencies = [ [[package]] name = "craft-image-codecs" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=fb6cb780061c6744ed6886e7dd1a80ccf449e655#fb6cb780061c6744ed6886e7dd1a80ccf449e655" +source = "git+https://github.com/storytold/craft-libs?rev=b16c5908ae777f81fa33a9e9ad0e22b09b37a383#b16c5908ae777f81fa33a9e9ad0e22b09b37a383" dependencies = [ "craft-jpeg", - "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=fb6cb780061c6744ed6886e7dd1a80ccf449e655)", - "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=fb6cb780061c6744ed6886e7dd1a80ccf449e655)", + "craft-metadata 0.1.0 (git+https://github.com/storytold/craft-libs?rev=b16c5908ae777f81fa33a9e9ad0e22b09b37a383)", + "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=b16c5908ae777f81fa33a9e9ad0e22b09b37a383)", "crc32fast", "exr", "flate2", @@ -1292,7 +1292,7 @@ dependencies = [ [[package]] name = "craft-jpeg" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=fb6cb780061c6744ed6886e7dd1a80ccf449e655#fb6cb780061c6744ed6886e7dd1a80ccf449e655" +source = "git+https://github.com/storytold/craft-libs?rev=b16c5908ae777f81fa33a9e9ad0e22b09b37a383#b16c5908ae777f81fa33a9e9ad0e22b09b37a383" dependencies = [ "thiserror 2.0.21", ] @@ -1310,11 +1310,11 @@ dependencies = [ [[package]] name = "craft-metadata" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18#f0f4758c01581d79577b9bf5046c06f4e77b1f18" +source = "git+https://github.com/storytold/craft-libs?rev=b16c5908ae777f81fa33a9e9ad0e22b09b37a383#b16c5908ae777f81fa33a9e9ad0e22b09b37a383" dependencies = [ "brotli-decompressor 6.0.1", "chrono", - "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=b16c5908ae777f81fa33a9e9ad0e22b09b37a383)", "quick-xml 0.41.0", "serde", ] @@ -1322,11 +1322,11 @@ dependencies = [ [[package]] name = "craft-metadata" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=fb6cb780061c6744ed6886e7dd1a80ccf449e655#fb6cb780061c6744ed6886e7dd1a80ccf449e655" +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=fb6cb780061c6744ed6886e7dd1a80ccf449e655)", + "craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18)", "quick-xml 0.41.0", "serde", ] @@ -1363,7 +1363,7 @@ dependencies = [ [[package]] name = "craft-tiff" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18#f0f4758c01581d79577b9bf5046c06f4e77b1f18" +source = "git+https://github.com/storytold/craft-libs?rev=b16c5908ae777f81fa33a9e9ad0e22b09b37a383#b16c5908ae777f81fa33a9e9ad0e22b09b37a383" dependencies = [ "serde", "thiserror 2.0.21", @@ -1372,7 +1372,7 @@ dependencies = [ [[package]] name = "craft-tiff" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=fb6cb780061c6744ed6886e7dd1a80ccf449e655#fb6cb780061c6744ed6886e7dd1a80ccf449e655" +source = "git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18#f0f4758c01581d79577b9bf5046c06f4e77b1f18" dependencies = [ "serde", "thiserror 2.0.21", diff --git a/Cargo.toml b/Cargo.toml index 8c48d8d6d6..086f45fcd6 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 = "fb6cb780061c6744ed6886e7dd1a80ccf449e655" } +craft-image-codecs = { git = "https://github.com/storytold/craft-libs", rev = "b16c5908ae777f81fa33a9e9ad0e22b09b37a383" } 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/tiff_codec.rs b/crates/codecs/src/tiff_codec.rs index 955756ca66..02395472c9 100644 --- a/crates/codecs/src/tiff_codec.rs +++ b/crates/codecs/src/tiff_codec.rs @@ -1,4 +1,4 @@ -//! TIFF decode via `craft-image-codecs` and header/IFD inspection via `craft-tiff`. +//! TIFF decode and header inspection via `craft-image-codecs`. use crate::convert::{Buf, Meta, Model, Raw, check_size, finish}; use crate::{DecodeOptions, Decoded, Error, Format, Result}; @@ -10,15 +10,9 @@ fn err(e: impl std::fmt::Display) -> Error { } pub(crate) fn decode(bytes: &[u8], opts: &DecodeOptions) -> Result { - let (tiff, complete) = craft_tiff::Tiff::parse_with_status(bytes, &Default::default()).map_err(err)?; - if !complete { - return Err(err("truncated TIFF")); - } - let ifd = tiff.ifds.first().ok_or_else(|| err("no IFD"))?; - let info = ifd.image().map_err(err)?; - check_size(F, info.width as u64, info.height as u64, opts)?; - let orientation = ifd.u16(craft_tiff::tags::ORIENTATION); - let bit_depth = info.bits_per_sample.first().copied().unwrap_or(8) as u8; + let info = craft_image_codecs::tiff_probe::decode_info(bytes, opts.max_pixels).map_err(probe_error)?; + let orientation = info.orientation; + let bit_depth = info.bit_depth; let ic_opts = craft_image_codecs::DecodeOptions { limits: craft_image_codecs::Limits { @@ -68,9 +62,13 @@ pub(crate) fn decode(bytes: &[u8], opts: &DecodeOptions) -> Result { /// as a decode would refuse it: a layout or compression we can't decode, or strips/tiles that /// start past the end of the file (truncated). The compressed data itself is not checked. pub(crate) fn header(bytes: &[u8]) -> Result<(u32, u32, u16)> { - craft_image_codecs::tiff_probe::header(bytes, DecodeOptions::default().max_pixels).map_err(|error| match error { + craft_image_codecs::tiff_probe::header(bytes, DecodeOptions::default().max_pixels).map_err(probe_error) +} + +fn probe_error(error: craft_image_codecs::tiff_probe::Error) -> Error { + match error { craft_image_codecs::tiff_probe::Error::TooLarge { width, height } => Error::TooLarge(u64::from(width), u64::from(height)), craft_image_codecs::tiff_probe::Error::Unsupported(reason) => Error::Unsupported(F, reason), craft_image_codecs::tiff_probe::Error::Malformed(message) => err(message), - }) + } } From 47742598afbfca8f5c61c6b33ba5547de59b4835 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 19:12:44 +0000 Subject: [PATCH 3/3] 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");