Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f6b8512
upstream #3720: a log message cannot start a record of its own
emmertex Nov 4, 2026
7bf3611
upstream #3718: geocode dumps are read from regular files with a size…
emmertex Nov 4, 2026
6fd5d97
upstream #3719: a TLS stream cut without close_notify is an error; re…
emmertex Nov 4, 2026
8f5231b
upstream #3696: cap XMP namespace declarations in scope
emmertex Nov 4, 2026
665e537
Upstream intake 2026-11-04: ledger for the second port batch
emmertex Nov 4, 2026
5548783
Merge remote-tracking branch 'origin/main' into upstream-intake-2026-…
emmertex Nov 4, 2026
1c6bfcd
upstream #3608: demo scenes render for any seed without integer overflow
emmertex Nov 4, 2026
38d918d
Upstream intake 2026-11-04: ledger for #3608 and #3627
emmertex Nov 4, 2026
74d8d1d
upstream #3677: moves refuse non-regular sidecars and packets
emmertex Nov 4, 2026
7a7748a
upstream #3645: bound HEIF alpha-grid tiles and hvcC parameter sets
emmertex Nov 4, 2026
83987b7
upstream #3717: cap Object selection clicks at the engine API and the…
emmertex Nov 4, 2026
03cb737
upstream #3697: lens database copy budget and regular-file reads
emmertex Nov 4, 2026
f8c372b
Upstream intake 2026-11-04: release note for the hand-ported hardening
emmertex Nov 4, 2026
9c11c7c
Upstream intake 2026-11-04: ledger for the hand ports
emmertex Nov 4, 2026
237cc5f
upstream #3713: app.memoryBudget refuses an mb that isn't a number
emmertex Nov 4, 2026
6fccb98
upstream #3646: ?bench runs on demo photos in an unsaved library, nev…
emmertex Nov 4, 2026
ecb9701
Upstream intake 2026-11-04: ledger for #3713, #3646 and #3596
emmertex Nov 4, 2026
eaa7352
upstream #3670: embed only fonts inside the asset checkout; no line b…
emmertex Nov 4, 2026
948998c
upstream #3721: test fixture directories are created exclusively
emmertex Nov 4, 2026
ee7ff53
upstream #3673: staging and probe files are created new, never writte…
emmertex Nov 4, 2026
41cf65b
Upstream intake 2026-11-04: ledger and note for #3670, #3721, #3673
emmertex Nov 4, 2026
9dd17d2
Merge remote-tracking branch 'origin/main' into upstream-intake-2026-…
emmertex Nov 4, 2026
6ac799a
upstream #3700: lossless ARW tile frames larger than half their tile …
emmertex Nov 4, 2026
617dd31
upstream #3676: the library folder is protected from folder.move howe…
emmertex Nov 4, 2026
ba3a0a3
upstream #3699: bound the alpha planes a render retains for masks
emmertex Nov 4, 2026
2153b8a
Upstream intake 2026-11-04: ledger and note for #3700, #3676, #3699
emmertex Nov 4, 2026
d36eb5f
upstream #3672: linear entity decoding, indexed keyword de-duplicatio…
emmertex Nov 4, 2026
ec6c0b3
upstream #3712: check caller-supplied image dimensions before sizing …
emmertex Nov 4, 2026
c6321ab
Upstream intake 2026-11-04: ledger and note for #3672 and #3712
emmertex Nov 4, 2026
03582f3
upstream #3703: read user-named files through the opened regular file…
emmertex Nov 4, 2026
a4b9d97
upstream #3641: bound keyword list path expansion and index synonym m…
emmertex Nov 4, 2026
347947c
Upstream intake 2026-11-04: ledger and note for #3703 and #3641
emmertex Nov 4, 2026
4a28a1b
upstream intake: rustfmt the ported hardening fixes
emmertex Nov 4, 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
23 changes: 21 additions & 2 deletions apps/app/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,19 @@ pub fn rotate(dir: &Path) -> std::io::Result<(PathBuf, File)> {
/// One formatted log line: `<timestamp> <LEVEL> [<thread>] <target>: <message>\n`.
pub fn format_line(ts: &str, level: log::Level, thread: &str, target: &str, message: &str) -> String {
let message = message.strip_suffix('\n').unwrap_or(message);
format!("{ts} {level:<5} [{thread}] {target}: {message}\n")
// A message can carry text from files and peers (a file name, a rejected value): it must not be able to start a
// record of its own. Later lines of a multi-line message (a panic report) are indented, so none begins like a
// record; other control characters (a bare CR, an escape sequence) are shown escaped (upstream #3720).
let mut safe = String::with_capacity(message.len());
for c in message.chars() {
match c {
'\n' => safe.push_str("\n "),
'\t' => safe.push(c),
c if c.is_control() => safe.extend(c.escape_default()),
c => safe.push(c),
}
}
format!("{ts} {level:<5} [{thread}] {target}: {safe}\n")
}

/// Where formatted lines go besides standard error: kept in memory until a file is attached,
Expand Down Expand Up @@ -657,6 +669,13 @@ mod tests {

/// The panic hook's report lands in the file, and never deadlocks when the panic happened
/// while this thread held the sink.
#[test]
fn a_message_cannot_forge_a_record() {
let forged = format_line("t", log::Level::Info, "w", "x", "name\r\n2026-01-01T00:00:00Z ERROR [main] x: fake\u{1b}[2J");
assert!(forged.lines().skip(1).all(|l| l.starts_with(' ')), "{forged:?}");
assert!(!forged.contains('\r') && !forged.contains('\u{1b}'), "{forged:?}");
}

#[test]
fn a_panic_report_goes_to_the_file_and_never_deadlocks() {
let dir = temp_dir("panic");
Expand All @@ -668,7 +687,7 @@ mod tests {
logger.record_panic("main", "while the sink is held");
}
let text = read(&path);
assert!(text.contains(" ERROR [render] app: panicked at crates/x/src/lib.rs:3:5:\nboom\n"), "{text}");
assert!(text.contains(" ERROR [render] app: panicked at crates/x/src/lib.rs:3:5:\n boom\n"), "{text}");
assert!(!text.contains("while the sink is held"), "{text}");
let _ = std::fs::remove_dir_all(&dir);
}
Expand Down
11 changes: 9 additions & 2 deletions apps/web/src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,12 @@ impl Options {
})
.collect();
let get = |k: &str| params.iter().find(|(n, _)| n == k).map(|(_, v)| v.clone());
let bench = get("bench").is_some();
Options {
bench: get("bench").is_some(),
store: get("store").filter(|s| s == "idb" || s == "memory").unwrap_or_else(|| "opfs".into()),
bench,
// the benchmark edits the first photo it finds: a link with `?bench` must never reach the library in
// browser storage, so it always runs on the demo photos in an unsaved library (upstream #3646)
store: if bench { "memory".into() } else { get("store").filter(|s| s == "idb" || s == "memory").unwrap_or_else(|| "opfs".into()) },
workers: get("workers").and_then(|v| v.parse().ok()),
reset: get("reset").is_some(),
}
Expand Down Expand Up @@ -474,6 +477,10 @@ impl WebApp {
});
}
}
// `?bench` never has storage (see `Options::from_url`): it measures the generated demo photos
if opts.bench && backend.is_none() && session.catalog.is_empty() {
lcc_engine::demo::load(&mut session);
}
if backend.is_some() {
notice(&lcc_brand::fill(
"{app} in the browser is experimental. Your library is kept in this browser's storage: keep your original photos \
Expand Down
105 changes: 83 additions & 22 deletions crates/catalog/src/keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ pub fn one_line(text: &str) -> std::borrow::Cow<'_, str> {
/// The deepest a keyword list file may nest keywords: a file is input, so its nesting is bounded.
pub const MAX_LEVELS: usize = 64;

/// The most bytes of full keyword paths a keyword list file may spell out. Every line names its
/// keyword by its whole path (`parent|child`), so a file of one long keyword with many short ones
/// inside it would otherwise grow into far more memory than its own size (CWE-400). Lightroom
/// Classic's own lists of tens of thousands of keywords come to a few MiB.
pub const MAX_LIST_PATH_BYTES: usize = 64 << 20; // 64 MiB

/// The deepest a photo's keyword, and so the keyword tree, goes: the tree is walked recursively
/// (here and in the panels), so an `a|a|a|…` keyword thousands of levels deep overflowed the stack.
pub const MAX_TREE_LEVELS: usize = 128;
Expand Down Expand Up @@ -157,6 +163,8 @@ pub fn parse_keyword_list(text: &str) -> Result<Vec<(String, KeywordInfo)>> {
let mut synonyms: std::collections::HashMap<usize, std::collections::HashSet<String>> = std::collections::HashMap::new();
// the keyword at each level above the line: its path and where it is in `out`
let mut above: Vec<(String, usize)> = Vec::new();
// bytes of full paths spelled out so far, checked against `MAX_LIST_PATH_BYTES` before each
let mut path_bytes = 0usize;
for (i, line) in text.split('\n').enumerate() {
let n = i + 1;
if line.trim().is_empty() {
Expand Down Expand Up @@ -205,6 +213,11 @@ pub fn parse_keyword_list(text: &str) -> Result<Vec<(String, KeywordInfo)>> {
return Err(bad(n, "“|” separates a keyword's levels: a name can't hold one"));
}
above.truncate(depth);
let parent_len = above.last().map_or(0, |(parent, _)| parent.len().saturating_add(1));
path_bytes = path_bytes.saturating_add(parent_len.saturating_add(name.len()));
if path_bytes > MAX_LIST_PATH_BYTES {
return Err(bad(n, &format!("the keywords' full paths come to more than {} MiB", MAX_LIST_PATH_BYTES >> 20)));
}
let path = match above.last() {
Some((parent, _)) => format!("{parent}{SEP}{name}"),
None => name.to_string(),
Expand Down Expand Up @@ -232,6 +245,14 @@ pub fn closest<'a>(k: &str, from: &'a [String]) -> Option<&'a String> {
from.iter().filter(|f| is_under(k, f)).max_by_key(|f| f.split(SEP).count())
}

/// Add each of `more` to `synonyms` that isn't there in any case, in order. One lowered set of
/// what is there, not a search of the growing list per synonym: an imported list can give a
/// keyword many synonyms, and the search was quadratic in them (CWE-407).
fn merge_synonyms(synonyms: &mut Vec<String>, more: impl IntoIterator<Item = String>) {
let mut seen: std::collections::HashSet<String> = synonyms.iter().map(|s| s.to_lowercase()).collect();
synonyms.extend(more.into_iter().filter(|s| seen.insert(s.to_lowercase())));
}

/// Keep the first of case-insensitively equal keywords.
fn dedupe(v: &mut Vec<String>) {
let mut seen = std::collections::HashSet::new();
Expand Down Expand Up @@ -361,11 +382,7 @@ impl Catalog {
match list.get_mut(&path.to_lowercase()) {
Some(there) => {
there.info.new_keywords_inside |= l.info.new_keywords_inside;
for s in l.info.synonyms {
if !there.info.synonyms.iter().any(|x| same(x, &s)) {
there.info.synonyms.push(s);
}
}
merge_synonyms(&mut there.info.synonyms, l.info.synonyms);
}
None => {
list.insert(path.to_lowercase(), ListedKeyword { path, info: l.info });
Expand Down Expand Up @@ -426,8 +443,11 @@ impl Catalog {
let defaults = KeywordInfo::default();
let info = |path: &str| self.keyword_info(path).unwrap_or(&defaults);
let mut out = ExportKeywords::default();
let push = |v: &mut Vec<String>, s: &str| {
if !s.is_empty() && !v.iter().any(|x| same(x, s)) {
// what each list holds, lowered: a search of the list per name was quadratic in a keyword's
// synonyms, which an imported list sets (CWE-407)
let (mut flat_seen, mut paths_seen) = (std::collections::HashSet::new(), std::collections::HashSet::new());
let push = |v: &mut Vec<String>, seen: &mut std::collections::HashSet<String>, s: &str| {
if !s.is_empty() && seen.insert(s.to_lowercase()) {
v.push(s.to_string());
}
};
Expand All @@ -440,11 +460,11 @@ impl Catalog {
let levels: Vec<&str> = path.split(SEP).collect();
let mut names = |at: usize, i: &KeywordInfo| {
if let Some(name) = levels.get(at) {
push(&mut out.flat, name);
push(&mut out.flat, &mut flat_seen, name);
}
if i.export_synonyms {
for s in &i.synonyms {
push(&mut out.flat, s.trim());
push(&mut out.flat, &mut flat_seen, s.trim());
}
}
};
Expand All @@ -458,7 +478,7 @@ impl Catalog {
}
}
}
push(&mut out.hierarchical, &path);
push(&mut out.hierarchical, &mut paths_seen, &path);
}
out
}
Expand All @@ -468,6 +488,13 @@ impl Catalog {
/// keyword, a keyword left out of export in square brackets; by name. What the format can't hold
/// is left out and named, so the file always reads back.
pub fn keyword_list_text(&self) -> KeywordListFile {
self.keyword_list_text_within(MAX_LIST_PATH_BYTES)
}

/// [`keyword_list_text`](Self::keyword_list_text) with the full paths written held to
/// `max_path_bytes` as [`parse_keyword_list`] holds them: a keyword past it is named
/// unwritable, with its subtree, so the file reads back.
fn keyword_list_text_within(&self, max_path_bytes: usize) -> KeywordListFile {
// a name the list would read as something else, or not at all
fn unwritable(name: &str) -> bool {
name.trim().is_empty()
Expand All @@ -478,14 +505,27 @@ impl Catalog {
|| (name.starts_with('[') && name.ends_with(']'))
|| (name.starts_with('{') && name.ends_with('}'))
}
fn write(c: &Catalog, nodes: &[KeywordNode], depth: usize, file: &mut KeywordListFile) {
fn write(
c: &Catalog,
nodes: &[KeywordNode],
depth: usize,
file: &mut KeywordListFile,
path_bytes: &mut usize,
max_path_bytes: usize,
parent_len: usize,
) {
let tabs = "\t".repeat(depth);
for n in nodes {
// the keywords inside go with it: under its parent they'd be other keywords
if depth >= MAX_LEVELS || unwritable(&n.name) {
// (a line's full path is what the reader counts against its path budget)
// the path the reader rebuilds from the lines written: the parent as emitted, a
// separator, the name (a child's `n.path` can spell its parent in another case)
let emitted = if depth == 0 { n.name.len() } else { parent_len + SEP.len_utf8() + n.name.len() };
if depth >= MAX_LEVELS || unwritable(&n.name) || path_bytes.saturating_add(emitted) > max_path_bytes {
file.unwritable.push(n.path.clone());
continue;
}
*path_bytes += emitted;
let info = c.keyword_info(&n.path).cloned().unwrap_or_default();
if info.include_on_export {
file.text.push_str(&format!("{tabs}{}\n", n.name));
Expand All @@ -495,23 +535,25 @@ impl Catalog {
file.written.push(n.path.clone());
// the reader trims synonyms and takes one per spelling: an empty one, or another's
// in a different case, is no loss; a line break or a “|” is
let mut synonyms: Vec<&str> = Vec::new();
// (one lowered set, not a search of those written so far per synonym: quadratic
// in a keyword's synonyms, which an imported list sets — CWE-407)
let mut synonyms: std::collections::HashSet<String> = std::collections::HashSet::new();
for s in info.synonyms.iter().map(|s| s.trim()) {
if s.is_empty() || synonyms.iter().any(|x| same(x, s)) {
if s.is_empty() || synonyms.contains(&s.to_lowercase()) {
continue;
}
if s.chars().any(char::is_control) || s.contains(SEP) {
file.unwritable.push(format!("{} {{{s}}}", n.path));
} else {
synonyms.push(s);
synonyms.insert(s.to_lowercase());
file.text.push_str(&format!("{tabs}\t{{{s}}}\n"));
}
}
write(c, &n.children, depth + 1, file);
write(c, &n.children, depth + 1, file, path_bytes, max_path_bytes, emitted);
}
}
let mut file = KeywordListFile::default();
write(self, &self.keyword_tree(), 0, &mut file);
write(self, &self.keyword_tree(), 0, &mut file, &mut 0, max_path_bytes, 0);
file
}

Expand Down Expand Up @@ -568,11 +610,7 @@ impl Catalog {
// one the library has: the list's synonyms join its own (listed only if it gains some)
let mut info_now = list.get(&key).map(|l| l.info.clone()).unwrap_or_default();
let before = info_now.synonyms.len();
for s in &info.synonyms {
if !info_now.synonyms.iter().any(|x| same(x, s)) {
info_now.synonyms.push(s.clone());
}
}
merge_synonyms(&mut info_now.synonyms, info.synonyms.iter().cloned());
if info_now.synonyms.len() > before {
let path = list.get(&key).map_or(path, |l| l.path.clone());
list.insert(key, ListedKeyword { path, info: info_now });
Expand Down Expand Up @@ -799,6 +837,29 @@ impl Catalog {
mod tests {
use super::*;

#[test]
fn synonym_merging_keeps_the_first_of_each_case_insensitive_name() {
let mut have = vec!["Sea".to_string()];
merge_synonyms(&mut have, ["sea", "Ocean", "OCEAN", "Surf"].map(String::from));
assert_eq!(have, ["Sea", "Ocean", "Surf"]);
let many: Vec<String> = (0..50_000).map(|i| format!("s{i}")).chain((0..50_000).map(|i| format!("S{i}"))).collect();
merge_synonyms(&mut have, many);
assert_eq!(have.len(), 3 + 50_000);
}

#[test]
fn a_keyword_list_whose_paths_spell_out_too_much_is_refused() {
// one 1 MB name, then children nesting under it: each line costs its whole path
let long = "x".repeat(1 << 20);
let mut text = format!("{long}\n");
for i in 0..70 {
text.push_str(&format!("\t{i}\n"));
}
// 70 lines of ~1 MiB path is 70 MiB, over the 64 MiB cap
let e = parse_keyword_list(&text).unwrap_err().to_string();
assert!(e.contains("full paths"), "{e}");
}

/// A camera preset's keyword list written as one `dc:subject` item, a keyword a line, is one
/// keyword a line; names stay one line wherever they are drawn.
#[test]
Expand Down
15 changes: 13 additions & 2 deletions crates/codecs/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,16 @@ impl<'a> EncodeImage<'a> {
if self.width == 0 || self.height == 0 {
return Err(Error::Encode("zero dimension".into()));
}
let need = self.width as u64 * self.height as u64 * self.channels as u64;
// u128: 2^32 x 2^32 x 4 does not fit u64, and every later `width * height * channels` is bounded by this
let need = self.width as u128 * self.height as u128 * self.channels as u128;
if need > usize::MAX as u128 {
return Err(Error::Encode("image too large".into()));
}
let have = match self.samples {
Samples::U8(s) => s.len(),
Samples::U16(s) => s.len(),
Samples::F32(s) => s.len(),
} as u64;
} as u128;
if have < need {
return Err(Error::Encode(format!("sample buffer too short: {have} < {need}")));
}
Expand Down Expand Up @@ -680,6 +684,13 @@ fn avif_10bit(enc: &ravif::Encoder, img: &EncodeImage, s: &[u16]) -> Result<Vec<
mod hlg_tests {
use super::*;

#[test]
fn dimensions_whose_sample_count_wraps_are_refused() {
// 2^31 x 2^31 x 4 is 2^64 samples: zero when wrapped, which an empty buffer would satisfy
let img = EncodeImage::new(1 << 31, 1 << 31, 4, Samples::U8(&[]));
assert!(img.validate().is_err());
}

#[test]
fn hlg_reference_white_and_peak() {
// BT.2408: SDR (HDR reference) white sits at 75 % HLG signal
Expand Down
19 changes: 19 additions & 0 deletions crates/codecs/src/gainmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,10 @@ pub fn encode_gain(gain: &GainImage, m: &GainMapMeta, quality: u8) -> Result<Vec
if !matches!(gain.channels, 1 | 3) || gain.width == 0 || gain.height == 0 || gain.data.len() < gain.width * gain.height * gain.channels {
return Err(Error::Encode("gain map image is malformed".into()));
}
// (jpeg_par::encode gives an empty JPEG past this, which would be appended as a size-0 gain map)
if gain.width > u16::MAX as usize || gain.height > u16::MAX as usize {
return Err(Error::Encode("JPEG dimensions are limited to 65535".into()));
}
if !m.is_valid() || m.multichannel != (gain.channels == 3) {
return Err(Error::Encode("gain map metadata doesn't match the map".into()));
}
Expand Down Expand Up @@ -843,6 +847,21 @@ mod tests {
}
}

#[test]
fn a_gain_map_wider_than_a_jpeg_allows_is_refused() {
let base = [0u8; 3];
let gain = GainImage { width: 65_536, height: 1, channels: 1, data: vec![0; 65_536] };
let r = encode_jpeg(
&EncodeImage::new(1, 1, 3, Samples::U8(&base)),
&gain,
&GainMapMeta::default(),
90,
ChromaSubsampling::S444,
&EncodeMeta::default(),
);
assert!(matches!(r, Err(Error::Encode(m)) if m.contains("65535")));
}

#[test]
fn jpeg_round_trip_and_container_structure() {
let (w, h) = (96, 64);
Expand Down
13 changes: 13 additions & 0 deletions crates/codecs/src/jpeg_par.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,12 @@ fn encode_with(
app_segments: &[(u8, Vec<u8>)],
optimize: bool,
) -> Vec<u8> {
// The public entry takes caller-sized dimensions: refuse (an empty output) what would size an allocation from
// them or index past `data`, rather than panic or allocate for them.
let fits = width.checked_mul(height).and_then(|n| n.checked_mul(channels)).is_some_and(|n| n <= data.len());
if !fits || width == 0 || height == 0 || width > 65_535 || height > 65_535 || !matches!(channels, 1 | 3 | 4) {
return Vec::new();
}
let gray = channels == 1;
let (hs, vs) = match (gray, sub) {
(true, _) | (false, ChromaSubsampling::S444) => (1usize, 1usize),
Expand Down Expand Up @@ -586,6 +592,13 @@ fn encode_with(
mod tests {
use super::*;

#[test]
fn hostile_dimensions_give_no_output_instead_of_a_panic_or_allocation() {
for (w, h, c) in [(1usize << 40, 1usize << 40, 3usize), (0, 8, 3), (70_000, 2, 3), (8, 8, 7), (8, 8, 3)] {
assert!(encode(&[0u8; 16], w, h, c, 90, ChromaSubsampling::S444, &[]).is_empty(), "{w} x {h} x {c}");
}
}

fn test_rgb(w: usize, h: usize) -> Vec<u8> {
let mut v = Vec::with_capacity(w * h * 3);
for y in 0..h {
Expand Down
Loading
Loading