From c17840e099d7a4237770bca99efb2693f1692a8d Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sun, 15 Nov 2026 11:21:36 -0500 Subject: [PATCH] Preserve LightCraft zero-padded entities with linear scanning Reuse LightCraft f786b87533e58c6d31c7f9f2897814904448f39a entity_end implementation and regression. XML numeric references are not arbitrarily length limited. --- crates/plist/README.md | 2 +- crates/plist/src/xml.rs | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/crates/plist/README.md b/crates/plist/README.md index 5621ef96a..a7adf6c79 100644 --- a/crates/plist/README.md +++ b/crates/plist/README.md @@ -14,6 +14,6 @@ Source: `storytold/craft-anything` at `88d1d9cac852aec1c7fd97886db451e005e49d2a` `parse_xml` and `parse_xml_with_limits` now read UTF-8 and BOM-tagged UTF-16 XML into the same `Value` tree. XML input/decoded-text size, tokens, values, nesting and cumulative key/leaf text are bounded. The independent token ceiling is eight times the smaller node/object allowance plus eight; unusually fragmented text can exhaust it before the value limit. This is not a precise RSS limit. The decoded-XML limit also includes markup; `` consumes its encoded text allowance, including whitespace. XML `max_objects` and `max_nodes` both cap values. -The attributed Craft Anything reader includes its complete-document, declaration-skipping (no external entity fetching), quoted-tag and normalized-line-ending behavior. Nonfinite reals are refused using contributor PR #1905. Unknown or malformed character references retain legacy literal behavior; scanning is bounded before searching for a terminator. Base64 retains that reader's legacy optional-padding/ASCII-whitespace behavior, including unused trailing bits; it is not a signature/key-validation API. No writer, JSON projection, keyed-archive interpretation or app policy is added. +The attributed Craft Anything reader includes its complete-document, declaration-skipping (no external entity fetching), quoted-tag and normalized-line-ending behavior. Nonfinite reals are refused using contributor PR #1905. Unknown or malformed character references retain legacy literal behavior; scanning stops at the next non-entity byte, preserving LightCraft's valid zero-padded numeric references without suffix rescans. Base64 retains that reader's legacy optional-padding/ASCII-whitespace behavior, including unused trailing bits; it is not a signature/key-validation API. No writer, JSON projection, keyed-archive interpretation or app policy is added. XML source: Craft Anything `8f3b775157d331dd31cfa4da911e26d8856b8c77`, plus #1905 `d85e104f093a334961048881bf003351e1ac4992`. The import credits Brandon Thomas and the existing hardening contributors; #1905 is authored by gmrmad1 and the quoted-tag/line-ending tests by RRFZ. Consumer cutovers require their own policy/parity tests, especially LightCraft's preset mapping and Craft Anything's projections. diff --git a/crates/plist/src/xml.rs b/crates/plist/src/xml.rs index c6cc4d022..be225d3fb 100644 --- a/crates/plist/src/xml.rs +++ b/crates/plist/src/xml.rs @@ -56,6 +56,12 @@ enum Tok { Text(String), } +// Ported from LightCraft f786b875: scan one entity-name run, never the remaining document. +fn entity_end(rest: &str) -> Option { + let n = rest.bytes().skip(1).take_while(|b| b.is_ascii_alphanumeric() || *b == b'#').count(); + (rest.as_bytes().get(n + 1) == Some(&b';')).then_some(n + 1) +} + fn decode_entities(s: &str) -> String { if !s.contains('&') { return s.to_string(); @@ -65,7 +71,7 @@ fn decode_entities(s: &str) -> String { while let Some(p) = rest.find('&') { out.push_str(rest.get(..p).unwrap_or("")); let after = rest.get(p..).unwrap_or(""); - let Some(end) = after.as_bytes().iter().take(13).position(|b| *b == b';') else { + let Some(end) = entity_end(after) else { out.push('&'); rest = after.get(1..).unwrap_or(""); continue; @@ -478,6 +484,7 @@ mod tests { assert_eq!(decode_entities(&(text.clone() + ";")), text + ";"); } assert_eq!(decode_entities("é&missing; & A"), "é&missing; & \r A"); + assert_eq!(decode_entities("Canon A"), "Canon A"); } #[test] fn caller_limits_refuse_before_unbounded_tree_growth() {