Skip to content

Native readers: 32-bit panics on a crafted record length or container count, and two work budgets that do not bound what they should #1815

Closed

Description

@DrunkOnJava

What

Four places where a crafted file can make a native reader panic or do unbounded work. Each was found by an audit of the parsing paths and checked line by line against main (314eeace).

  1. A panic on 32-bit targets. src/research/native_document.rs:785-797, group_records: end = start.checked_add(length)? on a u32 length read from the file, then end + 4 unchecked, in the comparison, the slice bytes[end..end + 4] and pos = end + 4. On a 32-bit target, a group whose length field is 0xFFFFFFF5 gives end = 0xFFFFFFFD. With overflow checks (CI's i686 job) end + 4 panics. Without them (wasm32, which the browser viewer runs on) it wraps to 1, and bytes[0xFFFFFFFD..1] panics. On 64-bit the ensure! refuses the group cleanly.
  2. A cylinder face's trim ring has no total point budget. src/research/native_saved_mesh.rs:769-776: ring calls ring_impl(..., EdgeSide::Cylinder, usize::MAX), so each crossing edge may be refined to EDGE_POINT_BUDGET (100,000) points and a loop of E edges holds E × 100,000. Planar faces: the point and work budgets of #1768 do not cover an edge's refinement before its ring is counted, or a face with regions #1770 closed the same gap for planar faces (PLANAR_FACE_POINT_BUDGET, 10,000), not for cylinders.
  3. STRIP_BUDGET does not count the work it bounds. src/research/native_parametric_mesh.rs:1127-1130 checks (u_knots.len() - 1) × segments.len() <= STRIP_BUDGET (20,000,000), while the trapezoid loop at :1184-1191 also walks v_knots for each trapezoid, so a hostile trim can ask for about strips × segments × v_knots, some 4e10 comparisons.
  4. The walker's two-column container read multiplies a file's count unchecked. src/walker.rs:2469-2475, read_field, Container { kind: 0x0e }: count is a u32 from the record, checked only against WalkerLimits::max_container_records (default 1,000, a public field), then col_bytes = 4 + count * 6 and total = 2 * col_bytes. A caller that raises the cap (usize::MAX reads as "no cap") gets an overflow panic on i686 for a count of 357,913,941 or more. trial_walk_checked reads the same wire shape with checked_mul and checked_add (:2294-2301).

Done when

  • (1) and (4) fail closed on every target, with a crafted repro in tests/fuzz_regressions.rs that reaches it through the public reader and fails the i686 overflow-checks job without the fix.
  • (2) and (3) are bounded, each by a value stated with why, and what a face over it becomes (refused, with which note) is shown on a synthetic input if no real file reaches it.
  • Every export of a real file is byte for byte as before: one unfiltered Measure (samples, Nordic, Revit 2025, held-out) against main, rows registered here first.

Found by Tendrils audit workers (DeepSeek) and checked by rvtDevelop; the code edits will be read line by line before they are pushed.

Activity

  1. changed the title [-]Native readers: a 32-bit panic on a crafted record length, and two work budgets that do not bound what they should[/-] [+]Native readers: 32-bit panics on a crafted record length or container count, and two work budgets that do not bound what they should[/+] on Nov 12, 2026
  2. DrunkOnJava commented on Nov 12, 2026

    @DrunkOnJava
    OwnerAuthor

    Expected results for af723ef (fix/1815-native-reader-bounds), registered before its Measure run:

    1. Exports unchanged. Every ifc.sha256 and every scorer file equals main's on an unfiltered run: samples, Nordic, Revit 2025, rac_advanced and the held-out models. No real face reaches CYLINDER_RING_POINT_BUDGET (20,000) or CUT_BUDGET (250,000,000), and no real group record reaches the overflow.
    2. Same-project gates pass on af723ef.
    3. native_group_record_length_overflow_does_not_panic passes on every target. On 64-bit its counts read (groups, unframed_groups) == (1, 1), which shows the crafted file reached group_records. Before the fix it panics on the i686 job; that job runs the fix, so the pass there is the evidence.
    4. The two trimmed_cells tests pass in cargo test --profile ci --lib. Without the counting, the hostile face is cut whole and the first test fails.

    On (4) of this issue, the walker's container: no crafted file can reach it through the public reader. read_adocument reads ADocument only at an offset where trial_walk_checked matched every field, with checked arithmetic over the same wire shape. A count large enough to overflow a 32-bit usize can't fit the bytes that trial needs, so the trial refuses the offset first. The fix keeps read_field safe on its own if a future caller skips the trial, but there is no repro for it. I'm stating that rather than writing a test that doesn't exercise the path.

  3. added a commit that references this issue on Nov 12, 2026
  4. DrunkOnJava commented on Nov 12, 2026

    @DrunkOnJava
    OwnerAuthor

    Row 3, measured: on scratch branch hotfix/red-1815-i686-repro (f26beccc: main 97397b9 plus only the new test, with no fix), the i686 overflow-checks job (run 43294376618, job 131448806688) fails on fuzz_regressions::native_group_record_length_overflow_does_not_panic alone (302 of 303 pass): "panicked at src/research/native_document.rs:791:13: attempt to add with overflow", the unchecked end + 4. With the fix (#1823) the same test passes there. The scratch branch is deleted.

  5. DrunkOnJava commented on Nov 12, 2026

    @DrunkOnJava
    OwnerAuthor

    Rows 1 and 2 hold on af723ef. In unfiltered Measure 43293778765, with samples, Nordic, BIMcollab, rac_advanced and the held-out models against main 97397b9:

    • 102 of 102 ifc.sha256 equal main's, and the scorer diff holds only the two head-only across-saves files;
    • all 18 semantic diffs read "no semantic difference";
    • the same-project gates pass on af723ef.

    9a5bf3b adds only a test, a doc comment, a changelog fragment and the dropped dev-dependency line on top, so these rows carry over to it. Row 3 is cited above, and row 4 runs in CI's --lib job.

  6. DrunkOnJava commented on Nov 12, 2026

    @DrunkOnJava
    OwnerAuthor

    #1823 lands (1) through (4) in code, but this issue stays open for two parts of its done-when:

    • (2): the cylinder ring budget is in place and Measure shows no real face reaches it. Its refusal (cylinder trim budget exceeded, the element drawn without its saved mesh) isn't yet shown on a synthetic face. ring_impl needs an object graph, and the tests have no builder for one; the pure ring_points_with count it uses is already tested.
    • (4): no crafted file can reach it through the public reader (see above). It's fixed as defense in depth, with no repro.

    Close this once (2) has its synthetic demonstration, or once (4) is accepted as unreachable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions