Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
6b7172b
Port storytold/lightcraft#1989: TIFF: read strips and tiles larger th…
emmertex Oct 17, 2026
afa0cb2
Port storytold/lightcraft#1935: raw: alias Canon EOS R6 Mark II to EO…
emmertex Oct 17, 2026
c120b05
Port storytold/lightcraft#1893: JPEG XL: size check before frames, wi…
emmertex Oct 17, 2026
6c87596
Port storytold/lightcraft#1894: HEIF: max_pixels on uncropped SPS siz…
emmertex Oct 17, 2026
6fc830b
Port storytold/lightcraft#1923: CRX high-frequency band width from th…
emmertex Oct 17, 2026
402c56d
Port storytold/lightcraft#1304: RW2: decode tiled format 8 (DC-S1RM2 …
emmertex Oct 17, 2026
821d47f
Port storytold/lightcraft#1165: folder import finds Sony SR2 and SRF …
emmertex Oct 17, 2026
1a12f81
Port storytold/lightcraft#2087 (part): a file-date guess never reache…
emmertex Oct 17, 2026
02b5b42
Port storytold/lightcraft#1284: NEF as-shot white balance from ColorB…
emmertex Oct 17, 2026
a86b5d8
Port storytold/lightcraft#1919: Hasselblad FFF colour matrix from the…
emmertex Oct 17, 2026
8657afa
Port storytold/lightcraft#1305: Blackmagic CinemaDNG 12-bit DCT JPEG …
emmertex Oct 17, 2026
26df8f3
Port storytold/lightcraft#1994: DNG: lossy JPEG XL tiles that declare…
emmertex Oct 17, 2026
bd76360
Port storytold/lightcraft#2003: Lightroom lossy DNGs: decode their JP…
emmertex Oct 17, 2026
b201c94
Port storytold/lightcraft#1891: Sony: Kelvin WB, focus points and fal…
emmertex Oct 17, 2026
3cd45bc
Port storytold/lightcraft#1901: Sony A7CR embedded distortion for cor…
emmertex Oct 17, 2026
c989089
Port storytold/lightcraft#1384: enable Sony ILCE-7M3 (A7 III) embedde…
emmertex Oct 17, 2026
c9601be
Port storytold/lightcraft#896: Nikon High Efficiency NEF (HE / HE sta…
emmertex Oct 17, 2026
ec0301b
Port storytold/lightcraft#672: decode two-field Coolpix NEFs (E5400, …
emmertex Oct 17, 2026
d705438
Port storytold/lightcraft#673: decode Nikon small raw (sRAW) NEFs as …
emmertex Oct 17, 2026
a858e86
Docs and branding for the upstream camera/format bundle
emmertex Oct 17, 2026
6eabfbc
Drop the ported MCP folder-discovery test: the fork's expand_paths_ta…
emmertex Oct 17, 2026
fe95a39
Port storytold/lightcraft#1165 follow-up: compare discovered paths wi…
emmertex Oct 17, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ image-webp = "0.2"
moxcms = { version = "0.9", default-features = false, features = ["lut"] }
jxl-oxide = { version = "0.12", default-features = false }
jixel = "=0.3.4" # BSD-3-Clause OR Apache-2.0, pure-Rust JPEG XL encoder (export; port of libjxl-tiny)
oxideav-jpegxs = { version = "0.0.8", default-features = false } # MIT, pure Rust entropy/DWT primitives for Nikon HE
zune-jpegxl = { version = "0.5", default-features = false, features = ["std"] } # MIT/Apache-2.0/Zlib lossless JXL encoder (test fixtures only)
ravif = { version = "0.13", default-features = false, features = ["threading"] } # no "asm": it needs nasm (non-Rust)
# HDR AVIF (PQ): ravif fixes the sRGB transfer curve, so HDR files drive its rav1e + avif-serialize directly
Expand Down
24 changes: 22 additions & 2 deletions crates/catalog/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ pub struct Photo {
/// ISO 8601 local capture time.
#[serde(default)]
pub captured: Option<String>,
/// The file's modification time, when import dated the photo by it because neither the file nor
/// its sidecar had a capture time (as Lightroom does). While [`Photo::captured`] is still this
/// guess, it is not a capture time anyone stated: it is never written to XMP, and a capture time
/// read from a sidecar later replaces it ([`Photo::captured_stated`]).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub captured_fallback: Option<String>,
pub imported: String,
#[serde(default)]
pub meta: Meta,
Expand Down Expand Up @@ -469,6 +475,7 @@ impl Photo {
height,
file_size: 0,
captured: None,
captured_fallback: None,
imported: imported.to_string(),
meta: Meta::default(),
rating: 0,
Expand Down Expand Up @@ -498,6 +505,11 @@ impl Photo {
video: None,
}
}
/// [`Photo::captured`], unless it is still the file-date guess import made
/// ([`Photo::captured_fallback`]): a capture time the file, a sidecar or the user stated.
pub fn captured_stated(&self) -> Option<&str> {
self.captured.as_deref().filter(|c| self.captured_fallback.as_deref() != Some(*c))
}
/// Sets [`Photo::preview_only`] as this build decided it, with its stamp.
pub fn set_preview_only(&mut self, preview_only: Option<String>) {
self.preview_checked = preview_stamp(&preview_only);
Expand Down Expand Up @@ -790,11 +802,19 @@ mod edited_tests {
("NIKON CORPORATION NIKON D850", "NEF", false),
("Canon Canon EOS 5D Mark III", "CR2", false),
("Canon Canon EOS R6m2", "CR3", false),
("Canon Canon EOS R6 Mark II", "CR3", false),
("Canon Canon EOS R7", "CR3", true),
("FUJIFILM X-T4", "RAF", false),
("ILCE-7M3", "ARW", false),
("SONY ILCE-7M2", "ARW", true),
("SONY ILCE-1", "ARW", true),
("SONY ILCE-7M2", "ARW", false),
("SONY ILCA-99M2", "ARW", false),
("SONY SLT-A33", "ARW", false),
("SONY ILCE-1", "ARW", false),
("SONY ILCE-1M2", "ARW", false),
("SONY ZV-E10M2", "ARW", false),
// the Sony bodies without presets, and a Sony sensor sold under another name
("SONY DSLR-A100", "ARW", true),
("HASSELBLAD Lunar", "ARW", true),
("", "ARW", true),
("SONY ILCE-7M3", "DNG", false),
] {
Expand Down
55 changes: 52 additions & 3 deletions crates/codecs/src/jxl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,67 @@ use crate::convert::{Buf, Meta, Model, Raw, check_size, finish};
use crate::space::{NamedSpace, SourceSpace, SpaceOrigin, Trc};
use crate::{DecodeOptions, Decoded, Error, Format, Result};
use jxl_oxide::color::{ColourSpace, EnumColourEncoding, Primaries, RenderingIntent, TransferFunction, WhitePoint};
use jxl_oxide::{AuxBoxData, JxlImage};
use jxl_oxide::{AllocTracker, AuxBoxData, InitializeResult, JxlImage};

const F: Format = Format::Jxl;

fn err(e: impl std::fmt::Display) -> Error {
Error::Malformed(F, e.to_string())
}

/// Bytes the decoder may hold per allowed pixel: four f32 channels, eight times over for frames,
/// extra channels and working buffers. The budget follows `max_pixels`, so oversized frames, extra
/// channels or modular trees inside an image of allowed size still fail (#1517).
const TRACKED_BYTES_PER_PIXEL: u64 = 4 * 4 * 8;

/// The allocation budget never drops below this, so small images keep the decoder's fixed
/// overhead (group buffers, entropy tables) whatever `max_pixels` is.
const MIN_TRACKED_BYTES: u64 = 64 << 20;

/// Bytes handed to the header stage at a time (the size `JxlImageBuilder::read` reads in).
const HEADER_CHUNK: usize = 4096;

/// Parses the header, checks the image size against `opts`, and only then reads the frames, with
/// an allocation budget, so a huge image is refused before any of its pixels are decoded
/// (`JxlImageBuilder::read` loads everything first).
fn open(bytes: &[u8], opts: &DecodeOptions) -> Result<JxlImage> {
let budget = opts.max_pixels.saturating_mul(TRACKED_BYTES_PER_PIXEL).max(MIN_TRACKED_BYTES);
let tracker = AllocTracker::with_limit(usize::try_from(budget).unwrap_or(usize::MAX));
let mut uninit = JxlImage::builder().alloc_tracker(tracker).build_uninit();
// Small slices, as `read` does: whatever the header stage has buffered when it initializes is
// parsed as frame data right away, so feeding the whole file here would skip the size check.
let mut rest = bytes;
let mut window = HEADER_CHUNK;
let mut img = loop {
let consumed = uninit.feed_bytes(rest.get(..window).unwrap_or(rest)).map_err(err)?;
rest = rest.get(consumed..).unwrap_or_default();
match uninit.try_init().map_err(err)? {
InitializeResult::Initialized(img) => break img,
InitializeResult::NeedMoreData(more) => uninit = more,
}
if consumed == 0 {
// the parser wants more than the window holds at once
if window >= rest.len() {
return Err(err("truncated JPEG XL header"));
}
window = window.saturating_mul(2);
}
};
check_size(F, img.width() as u64, img.height() as u64, opts)?;
while !rest.is_empty() {
let consumed = img.feed_bytes(rest).map_err(err)?;
if consumed == 0 {
break;
}
rest = rest.get(consumed..).unwrap_or_default();
}
img.finalize().map_err(err)?;
Ok(img)
}

pub(crate) fn decode(bytes: &[u8], opts: &DecodeOptions) -> Result<Decoded> {
let mut img = JxlImage::builder().read(std::io::Cursor::new(bytes)).map_err(err)?;
let mut img = open(bytes, opts)?;
let (w, h) = (img.width(), img.height());
check_size(F, w as u64, h as u64, opts)?;
let header = img.image_header();
let bits = header.metadata.bit_depth.bits_per_sample() as u8;
let float = matches!(header.metadata.bit_depth, jxl_oxide::image::BitDepth::FloatSample { .. });
Expand Down
3 changes: 3 additions & 0 deletions crates/codecs/src/tiff_codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ pub(crate) fn decode(bytes: &[u8], opts: &DecodeOptions) -> Result<Decoded> {
fn limits(opts: &DecodeOptions) -> Limits {
let mut limits = Limits::default();
limits.decoding_buffer_size = opts.max_pixels.saturating_mul(4 * 8).min(usize::MAX as u64) as usize;
// One strip or tile is read whole: the default 128 MiB refuses a single-strip uncompressed 16-bit
// export of ~22 MP (#1983). The same cap as the decoded image (32 bytes per allowed pixel) bounds it.
limits.intermediate_buffer_size = limits.decoding_buffer_size;
limits.ifd_value_size = 32 << 20;
limits
}
Expand Down
38 changes: 38 additions & 0 deletions crates/codecs/tests/roundtrip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,28 @@ fn tiff_cmyk_and_orientation() {
assert!(red[0] > 0.99 && red[1] < 0.01 && red[2] < 0.01, "{red:?}");
}

/// An uncompressed 16-bit RGB export in a single strip, the shape of the file in #1983 (3923 × 5877,
/// 138 MB). Its one strip is larger than the `tiff` crate's default 128 MiB intermediate buffer, so
/// the thumbnail (and the full decode) failed with "decoder limits exceeded".
#[test]
fn tiff_single_strip_larger_than_128_mib() {
use tiff::encoder::{TiffEncoder, colortype};
let (w, h) = (3923u32, 5877u32);
let mut cur = std::io::Cursor::new(Vec::new());
{
let mut enc = TiffEncoder::new(&mut cur).unwrap();
let mut im = enc.new_image::<colortype::RGB16>(w, h).unwrap();
im.rows_per_strip(h).unwrap();
im.write_data(&vec![0x8000u16; (w * h * 3) as usize]).unwrap();
}
let bytes = cur.into_inner();
assert!(bytes.len() > 128 << 20);
let t = decode_thumbnail(&bytes, 256).unwrap();
assert_eq!((t.source_width, t.source_height), (w, h));
let px = t.image.get(10, 10);
assert!(px[0].abs_diff(128) <= 2 && px[0] == px[1] && px[1] == px[2], "{px:?}");
}

/// A one-strip, uncompressed, single-sample TIFF (little-endian) whose samples are `bits` wide and
/// already packed into `strip`, one padded row after another.
fn packed_tiff(width: u16, height: u16, bits: u16, photometric: u16, strip: &[u8]) -> Vec<u8> {
Expand Down Expand Up @@ -735,6 +757,22 @@ fn jxl_lossless_exact_with_metadata() {
assert!(max_diff(&d.image, &want.image) < 1e-5, "16-bit lossless differs by {}", max_diff(&d.image, &want.image));
}

/// #1517: the size limit is checked from the header, before any frame is read, and a
/// file cut anywhere is an error, never a panic.
#[test]
#[cfg(feature = "jxl")]
fn jxl_size_limit_and_truncation() {
let b = encode_jxl(&EncodeImage::rgba8(&gradient(97, 61)), &JxlOptions { lossless: true, ..Default::default() }, &EncodeMeta::default()).unwrap();
let r = decode(&b, DecodeOptions { max_pixels: 97 * 61 - 1, ..Default::default() });
assert!(matches!(r, Err(Error::TooLarge(97, 61))), "{r:?}");
let d = decode(&b, DecodeOptions { max_pixels: 97 * 61, ..Default::default() }).unwrap();
assert_eq!((d.width, d.height), (97, 61));
for cut in [0, 1, 2, 5, 12, 40, b.len() / 2, b.len() - 1] {
let _ = decode(&b[..cut], DecodeOptions::default());
}
assert!(decode(&b[..12.min(b.len())], DecodeOptions::default()).is_err());
}

#[test]
#[cfg(feature = "jxl")]
fn jxl_lossy_quality_and_effort() {
Expand Down
Loading
Loading