Skip to content

fix(research): an element index row's layout and a graphics branch's curves-only check are held to a step budget, so a crafted schema or graph cannot take exponential time (#1833) - #1835

Merged
DrunkOnJava merged 1 commit into
mainfrom
fix/1833-exponential-layout-and-curve-walks
Nov 12, 2026

Conversation

@DrunkOnJava

@DrunkOnJava DrunkOnJava commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Summary

This bounds the two exponential cases on #1833's list, A and B, by counting the steps each takes:

  • An element index row's layout can now take at most 10,000 class visits and fields.
  • A graphics branch's curves-only check can now make at most 100,000 calls.

No real file should change; the Measure run checks that.

Motivation

Part of #1833: A and B, the two exponential cases. The other sixteen are polynomial and stay open there. Tendrils audit workers found them, a second worker confirmed each, and I re-read both against main.

Changes

  • src/research/native_index.rs, fixed_layout:
    • Before: the only bound was depth < 128, so a schema whose classes each name the next twice (base == 14) took 2^127 visits. Every native read reaches it, through native_preamble.
    • Now: each visit adds one, plus the fields of its class, to a count held to LAYOUT_STEP_BUDGET, 10,000. That count also bounds the leaves and the row's size.
    • Why 10,000: an ElemTable row is 28 or 40 bytes, so a real layout has at most 40 leaves.
    • Over the budget: the read is refused as index layout step budget.
  • src/research/native_graphics_traversal.rs, only_curves:
    • Before: seen held only the current path, so a child shared at every level was walked once per path, up to 2^128 calls. visit stops at 100,000 visits; this check did not count against that. The default export's saved-graphics pass and the viewer reach it.
    • Now: the path and a call count are one CurveWalk, held to CURVE_CHECK_BUDGET, 100,000, the same as visit's limit. A filter's children share one walk, so the budget is per decision, not per child. The path is emptied after each child, as it was.
    • Over the budget, a branch is not curves only. A filter's children are then walked under visit's own limit, and a component gets VIEW_COMPONENT_DIAGNOSTIC.
    • The one way a valid file could change: a filter whose curve-only descendants take more than 100,000 calls in all. It was excluded at once before; now it is walked, and lands as partial or with that diagnostic. A large linework or annotation group could do that. The Measure run checks diagnostics.json per model for excluded_non_surface_branches and the saved-mesh refusals. If one moves, a fresh walk per child, as the old HashSet was, still bounds each child and changes nothing under it.
  • changelog.d/security/1833-exponential-layout-and-curve-walks.md.

Testing

  • Unfiltered Measure against main on 74a15d6d (samples, families, Nordic, Revit 2025, BIMcollab, rac_advanced, held-out): 43305451837. Every export and diagnostics hash should equal main's. A real file over either budget would change its export there.

  • No repro. Each case needs a crafted schema or object graph to reach it through the public reader. Each was verified by reading.

  • tools/check-local.sh: not run locally (no local builds); CI runs it

  • Real files: the unfiltered Measure

Audit-honesty checklist

Legal and contribution hygiene

  • Apache-2.0; no Autodesk source

Breaking changes

None. Both functions are private.

https://claude.ai/code/session_01L1QUmYwb7cHmeCQU8FD2Ge

…curves-only check are held to a step budget, so a crafted schema or graph cannot take exponential time (#1833)

fixed_layout was bounded only by depth: a chain of classes each naming the
next twice took 2^127 visits. It now counts each class visit and field
against LAYOUT_STEP_BUDGET (10,000; a real ElemTable row has at most 40
leaves). only_curves kept only the current path, so a child shared at every
level was walked once per path; it now counts its calls against
CURVE_CHECK_BUDGET (100,000, the graphics walk's own limit), and a branch
over it is not curves only.

Claude-Session: https://claude.ai/code/session_01L1QUmYwb7cHmeCQU8FD2Ge
@DrunkOnJava
DrunkOnJava merged commit 080238c into main Nov 12, 2026
65 checks passed
DrunkOnJava added a commit that referenced this pull request Nov 12, 2026
…ids, sketch loops, empty faces, parameter bindings and family mesh checks are read through an index or under a work budget, so a crafted file cannot hang them (#1833) (#1849)

## Summary

This bounds the rest of #1833: the readers that did work growing with
the square or more of a count a crafted file sets. Each is fixed at its
root. Where an index answers, the reader builds it once. Where none can,
the reader counts its work against a budget no real model comes near.
Past the budget, it leaves the element as an unread stream leaves it.

Every remaining #1833 site is here. The final unfiltered Measure runs on
the head.

## Motivation

Part of #1833. A and B are #1835; J, O and P are #1847. The designs came
from Tendrils workers, a challenger tested each one's premises, and I
re-read and reworked each against `main`. The challengers found eight of
the sixteen designs flawed, and their cases shaped what is here. The
plan with each site's repair is kept with the batch.

## Changes

- **C, D, E** `src/research/partition_pipe_axes.rs`:
- `scan_pipe_end_keys` keeps each end's keys in order with a set beside
them, where a `contains` made it quadratic.
- `BoxGrid::new` stops, giving `None`, past `MAX_GRID_CELLS` (1,024
boxes at the per-box cap). Before, the per-box cap had no total.
- The connector scans count each entry's near boxes or ends against
`MAX_CONNECTOR_TESTS` (1e8). Past it they give nothing for the file.
They do not truncate, since a match never reached could have decided a
pipe (the challenger's case: a tie).
- **F** `src/research/partition_curve_fields.rs`: the windows' entries
and the boxes each is tested against count against the same budget, and
a grid over its cells is skipped. The window is not narrowed: the
challenger showed that could move a real element.
- **G** `src/research/partition_room_parameters.rs`:
- The three text, integer and name scans find each hit's data object in
the stream's listed objects (`memoised_partition_data_objects`,
`data_object_owner`), where each hit searched 200,000 bytes back. On the
local corpus no verified header lies inside a listed object, so the
owner is the one `enclosing_data_object` found.
- `data_objects` reads each header's Adler-32 from sums kept every 256
bytes along the stream, so a header costs at most two blocks of reading
whatever its size, and the pass is linear with no budget.
- The first version capped verification at four times the stream. That
cap was never measured, and real streams pass it. Headers that pass the
size checks and fail their checksum cover Core Interior's
`Partitions/46` 31.7 times over, one of them 94 MB of 99 MB. RE1
Architecture and Electrical reach 12.7x. The cap dropped nearly every
data object (Corpus health, 9 tests).
- Checked by a replica: 3,006 random ranges equal zlib's Adler-32, and
the listing equals the full-checksum listing on every partition of Core
Interior and RE1 Electrical.
- **H** `src/research/partition_room_boundaries.rs`: the export reads
`solid_headers_for`, which keeps headers for the stream's rooms alone,
at most `MAX_SOLIDS_PER_ROOM` (16) each. A room is stored once or twice;
past that it keeps its box. Probes keep the unbounded
`solid_headers_by_id`.
- **I** `src/research/element_record_plan_profiles.rs`: the loop solve
charges each vertex lookup, edge check and candidate pair against
`SOLVE_WORK_BUDGET` (1e8 a sketch owner) before it is spent.
- A slab's sketch has tens of lines (Core Interior's plates own 57,
RE-95).
- Past it the owner has no plan profile and keeps its box. Each owner
needs its own records, so the whole is linear in the file.
- **K** `src/research/native_empty_faces.rs`: `EmptyTrimIndex` walks a
graph once and answers every face. The saved-mesh pass keeps one per
owner graph. Each answer is the one the per-face walk gave, which the
challenger checked case by case.
- **M** `src/reader.rs`: the `header_hits` memo is held under 64 MiB,
dropped whole past it (RE-144: 0.4 MiB at most on the reference models).
A reader keeps its `Arc`.
- **Each stop is reported** (`src/budget.rs`, `src/reader.rs`,
`src/ifc/mod.rs` `record_work_budget_stops`). A budget site notes its
stop (`budget::stopped("pipe_connector_tests")`, and so on). The export
writes a `work_budget_reached` skipped item counting each reader's
stops, and a `Work budget reached:` warning per reader, as it does for a
stream a limit kept out.
- The readers that stop hold no handle, so each notes on its thread. A
`budget::Notes` collects what is noted under the walk and under each
export, and the handle keeps it, as it keeps its unread streams. The
walk is memoised on the handle and holds every site here, so a second
export, or an export after `elements()`, reads it back and still reports
the stops.
- A note under no `Notes` is dropped: a reader called on its own, or on
a saved-mesh worker thread. Every site here runs on the export's thread.
- `ExportDiagnostics::is_partial` is the one test of an incomplete
export: an unread stream or a budget stop. `rvt-ifc` and `rvt-gltf`
print the readers that stopped and exit 3 unless `--allow-partial`, as
for an unread stream. Python's `write_ifc` raises `ValueError` unless
`allow_partial=True`. The MCP server's exports refuse unless
`allow_partial`, and list the readers in `notes` and `partial`.
- The export-decisions count contract
(`tests/export_decisions_counts.rs`, the schema text and
`docs/export-diagnostics.md`) exempts the item, as it exempts
`stream_not_read_resource_limit`: it counts stops, not elements.
- **`changelog.d/security/1833-work-budgets.md`**.

- **N** `src/research/native_parameter_definitions.rs`:
- `seal_bindings`, called where the definitions pass ends, matches each
(category, kind) a binding names once, with its backlink check.
`matching_bindings` reads that answer.
- Before, every record of a category rebuilt every matching definition's
backlinks. Same order, same keys.
- A failure keeps the message `error.to_string()` gave, which is all the
record's diagnostic keeps. An unsealed registry computes as before.
- **Q** `src/research/native_form_geometry.rs`:
- The mesh comparison counts `surface_samples`' points and makes only
the ones its stride takes, each from its place in that order
(`SurfacePlan`). The points and the max are the same.
- Before, every point was made first, up to millions for a crafted
family. The probe keeps `surface_samples`.
- **R** `src/research/partition_scanner.rs`: each stream scan takes the
cap's remainder, the pattern `partition_arc_walls` uses. The candidates
kept are the same first ones, and a stream can no longer double the cap.
- The default stays `None` (the caller's choice; a research API with no
in-tree caller). Setting one needs per-file totals over the corpus
first, which the challenger asked for.

- **L** `src/reader.rs`: the inflated-partition memo is held under
`INFLATED_MEMO_BUDGET_BYTES`, 16 GiB (Griffin, 2026-11-12, "Bound it at
16 GiB").
  - Each stream's inflate was capped, but not their sum.
- No real file comes near: the 1.13 GB client model peaks at 5.1 GB in
all (docs/viewer-api.md).
- Past it the memo is let go before the next stream joins, and a reader
keeps its `Arc`.
- Partition progress now counts each stream inflated once, held or not,
so a release no longer lowers it (the challenger's note on
`release_inflated_partitions`).

## Testing

- Unfiltered Measure, timed, against the merge-base `8421e655` on
`13324f32`:
[43324820431](https://github.com/DrunkOnJava/rvt-rs/actions/runs/43324820431).
It replaces 43320809907, cancelled once Corpus health showed the first
data-object cap dropping data on real files.
- Every export and diagnostics hash equals the base's: `ifc.sha256` on
146 of 146 models and `diagnostics.json` on 121 of 121. Every scorer
file is equal too; the only difference is output the head alone writes
(`probe.txt`, `areas_across_saves*`). No real file reaches a budget: one
that did would move its pipes' ports, curve fields, room parameters,
room outlines, slab profiles, saved-mesh counts, the parameter sets of
`--revit-property-sets` or the family extrusions' mesh agreement, and
its diagnostics would name the stop.
- Timing row, registered before the run: median head/base at or below
1.00 over the 2023 to 2027 samples, no file above 1.03. **It holds:**
median 0.962 (0.917 to 1.007) over those 29 samples, and none more than
3% slower. The models' median is 0.958, since the range sums read each
data object's checksum from two blocks instead of its whole payload.
- Peak memory was not a registered row. Every group's median is 1.000.
Snowdon Plumbing reads 473 MiB at the base and 497 at the head (1.051),
and Snowdon HVAC 250 and 235 (0.94). The base commit `8421e655` itself
reads 474 and 496 for Plumbing and 235 for HVAC in run 43317496752, so
both files land in one of two peaks run by run, whatever the code.
- No repro. Each site needs a crafted file of thousands of elements.
Each was verified by reading. No run exercises the new exit-3 path,
since no real file stops.

- [ ] `tools/check-local.sh`: not run locally (no local builds); CI runs
it
- [x] Real files: the unfiltered Measure

## Audit-honesty checklist

- [x] No claim beyond what ships; R's default stays open on #1833, with
why; the exit-3 path for a budget stop is not exercised by any run
- [x] Security changelog fragment
- [x] No emojis or private paths

## Legal and contribution hygiene

- [x] Apache-2.0; no Autodesk source

## Breaking changes

None. Two new stable methods, `ExportDiagnostics::is_partial` and
`ExportDiagnostics::work_budget_stops`, and
`rvt::cli::work_budget_report`. In `rvt::research` there are two new
items, `solid_headers_for` and `EmptyTrimIndex`, plus
`MAX_SOLIDS_PER_ROOM`. `rvt-ifc` and `rvt-gltf` exit 3 where a reader
stopped at a work budget, which no real file does.

https://claude.ai/code/session_01L1QUmYwb7cHmeCQU8FD2Ge
@DrunkOnJava
DrunkOnJava deleted the fix/1833-exponential-layout-and-curve-walks branch November 14, 2026 14:07
DrunkOnJava added a commit that referenced this pull request Nov 15, 2026
…y default and says so, from what the 28 real files of Revit 2023 and 2024 keep (#1833) (#2031)

## Summary

`ScanOptions::default()` now stops at 16,777,216 candidates (2^24), and
`PartitionScan::truncated` says when a scan reached the cap. It was the
one site of #1833 left: the research API's partition scanner, which kept
every schema tag followed by two zero bytes with no limit.

## Motivation

#1833 site R: a stream holds up to one candidate for every four of its
bytes, and each takes about 250 bytes (160 inline, and three short
strings), so a crafted stream could take about 67 GB of candidates from
the 1 GiB the reader lets a stream inflate to. The comment on #1833 said
a default cap needs the candidate totals of real files first, so that it
never cuts a real scan. This is that measurement.

**Measured** (Measure
[43663157788](https://github.com/DrunkOnJava/rvt-rs/actions/runs/43663157788),
`probe_1833_scan_candidates`, the 28 files of Revit 2023 and 2024 it
read; the scanner returns nothing on other releases):

- The most candidates in one file: 9,675,757 (the BIM4LCA timber office
at building permit, 696 MB inflated, 59 streams).
- The most in one stream: 6,531,651 (Autodesk's Snowdon Towers
architectural sample).
- The fullest stream holds 14.7% of the one-in-four-bytes maximum (the
BIM4LCA office at permit). The median file holds one candidate for every
82 bytes, and the range is 57 to 171.
- A candidate is 160 bytes inline (printed by the probe). The strings'
heap is counted at 3 x 32 bytes and is not measured.

So the default is 2^24, 1.7 times the most any of them keeps. A real
file at that figure takes about 2.4 GB of candidates today, so the cap
does not make the research scan cheap; it stops a crafted stream at
about 4 GB where it could take 67 GB.

## Changes

- `src/research/partition_scanner.rs`: `DEFAULT_MAX_CANDIDATES` (2^24)
with the measurement in its doc comment, the default `ScanOptions` and
`arcwall_2023_only` use it, `PartitionScan::truncated`
(`#[serde(default)]`), a "Budget" section in the module docs.
- `examples/partition_scanner_json.rs`: keeps the default cap unless
`--max-candidates` or the new `--no-cap` is given (it set `None` when
the flag was absent), and prints `truncated`.
- `probes/examples/probe_1833_scan_candidates.rs`: the probe, which
prints `truncated` too.
- `tests/partition_scanner.rs`: a real-file check
(`einhoven_scan_says_when_it_reached_the_cap`): Einhoven's default scan
is not truncated, and with `max_candidates` 10 the scan is truncated and
lists the first 10 candidates of the whole scan.
- `changelog.d/security/1833-scan-candidates-cap.md`.

## Testing

Measure
[43664481547](https://github.com/DrunkOnJava/rvt-rs/actions/runs/43664481547),
unfiltered against the merge base, with samples, nordic, r2025 and
holdout, and the probe run
[43664485165](https://github.com/DrunkOnJava/rvt-rs/actions/runs/43664485165)
on the 2023 and 2024 files. Rows registered before they are read:

1. Every export and every `diagnostics.json` is byte for byte the merge
base's: nothing in the export or the CLIs calls the scanner. **Held**
(run 43664481547, head `0dd5143c`, the commit holding every `src`
change; the later commit adds a test): 120 of 120 exports and 102 of 102
`diagnostics.json` identical to the merge base.
2. The probe reports `truncated=0` on all 28 files and the same
candidate counts as run 43663157788. **Held** (run 43664485165, head
`0dd5143c`): `truncated=0` on all 28 supported files, and release, scan,
streams, inflated bytes, candidates, largest stream and fill are
identical to run 43663157788 on all 33 models, the most candidates in a
file still 9,675,757.
3. `same-project gates` pass. **Held** on `0dd5143c`: 15 samples held to
their earlier saves, and the Areas on 4 saves and on the 2021 save; the
semantic diff finds no difference in 42 models.

- [ ] `tools/check-local.sh`: no local builds; `rustfmt --check` passes;
CI runs the rest.

## Audit-honesty checklist

- [x] The figures above are from the run named; the 250 bytes per
candidate is arithmetic on the measured 160 plus an assumed 96 for the
strings, and the changelog says "about".
- [x] A changelog fragment.
- [x] No emojis, private paths or jargon.

## Legal and contribution hygiene

- [x] Apache-2.0; no Autodesk source; no fixtures.

## Breaking changes

`PartitionScan` gains a field, and `ScanOptions::default()` now caps the
scan. Both are in `rvt::research` (behind `unstable-research`). A caller
that needs more than 2^24 candidates sets `max_candidates` to `None`.

Closes #1833: sites A to Q landed in #1835, #1847 and #1849, and this is
R.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant