Repository navigation
fix(partitions): the partition scanner no longer reads one byte past a buffer whose last tag is followed by a zero - #1137
Merged
Conversation
…a buffer whose last tag is followed by a zero scan_partition_buffer looped offsets to len - 3 and checked the two bytes after a matching tag, so a tag in the last three bytes followed by a zero byte read buf[len] and panicked: hostile input could abort the research scanner (found reviewing #1136). A candidate needs both bytes, so the loop now ends at len - 4 (the function already returns early below four bytes); every output is unchanged. tests/fuzz_regressions.rs (hardening, run in CI) replays such buffers of 4 to 11 bytes.
DrunkOnJava
commented
Oct 30, 2026
DrunkOnJava
left a comment
Owner
Author
There was a problem hiding this comment.
Maintainer self-review. GitHub does not let a PR's author approve it, so this review stands in for an approval: I read the full diff and checked each claim.
- Panic path:
scan_partition_bufferreturns early unlessbuf.len() >= 4, sobuf.len() - 4cannot underflow. At every offset the loop now visits, it readsoffset + 3at most, inside the buffer, andread_envelopereads onlyoffset + 2..=offset + 3before its own bounds checks. - No output changes: the only offset dropped is
len - 3. There a tag either had a non-zero third byte, which was skipped, or a zero one, which panicked. It could never produce a candidate. - Verified:
fuzz_regressions::partition_scan_tag_in_the_last_three_bytes_does_not_panicran and passed in the hardening class (build + real files / ubuntu-24.04 / stable), andCI passed. Onmain's code those buffers indexbuf[len].
Ready to land.
DrunkOnJava
added a commit
that referenced
this pull request
Oct 30, 2026
…elper, and one ArcWall scan per file (#1136) ## Summary The audit's helper refactor (Griffin, 2026-10-30, "One copy of each helper"): copied helpers become one shared copy each, little-endian reads go through `le_bytes` where the conversion is exactly equivalent, and the partition ArcWall scan runs once per file instead of up to four times. Nothing an export writes should change; Measure checks that. ## Changes - **`le_bytes`:** about 117 of 227 inline `from_le_bytes` reads now use `le_bytes`, which gains `i32_at` and `u16_units`. The rest are left because their failure semantics differ: `Result` errors with specific messages, `InstanceField::Bytes` fallbacks in `walker.rs`, cursor `take(n)?` reads, fixed-size arrays that cannot fail, and `src/bin`. A raw-indexed read behind an explicit bounds check becomes `?` only where that check makes the new `None` arm unreachable. Messages from `anyhow` errors are kept word for word. - **`find_subslice`:** one copy, memchr, with the empty-needle guard kept. It replaces two wrappers and one scalar loop. - **GUID:** one `guid_string`, now used by three readers. One IFC GlobalId alphabet. `derive_default_ifc_guid` calls `compress_ifc_guid`. - **`src/native_json.rs` (research):** `element_id`, `element_id_i64`, `finite_triple` and `agree`, shared by twelve `native_*` and partition modules. Variants with different semantics stay. - **`src/vector_math.rs` (private):** `sub`, `dot`, `cross`, `distance` and `polygon_area_xy`. Expressions are token-identical to the copies they replace. `from_decoded::polygon_area_sqft` keeps its public path. The three point-in-polygon copies and the signed areas differ and stay. - **Storeys:** one `elevation_storey_name`. - **ArcWall scan:** memoised on `RevitFile` per release and `WalkerLimits` (`memoised_arc_wall_scan`). The production walk, the partition assembler and both IFC-export sites share it. The public `scan_partition_arc_walls_with_limits` keeps its signature. - `changelog.d/changed/arc-wall-scan-memo.md`. No public signature changes. `fuzz/` and `rvt-probes` call public items only. ## Testing - No local build, by policy. A side agent wrote the commits, and I read every diff. - The branch's new `use crate::le_bytes;` imports made four `crate::le_bytes::` paths already on `main` redundant, which `unused_qualifications` (an error under `-D warnings`) would have rejected. They are fixed in `ac976268`. - CI is the compiler, with clippy and rustdoc under `-D warnings`, MSRV and i686. - Measure [41037020175](https://github.com/DrunkOnJava/rvt-rs/actions/runs/41037020175), unfiltered against `main` with nordic and r2025: - The other 30 models are byte-identical on both sides: every `ifc.sha256`, every `diagnostics.json` and all scorer outputs (1,262 files on the head side). - The BIM4LCA office's host was unreachable during the base run, so the office was **NOT MEASURED** on the `main` side. - Its head-side export, diagnostics and every scorer output are instead identical to those of #1074's head (run 41025987689, commit 60be7324). Every PR merged since then (#1133, #1134, #1135, #1137) leaves the export path untouched. - `CI passed`, including clippy and rustdoc under `-D warnings`, MSRV and i686. ## Found, not changed `partition_scanner.rs:239/449` can index `buf[offset + 3]` past the end when a tag matches in a buffer's last three bytes. That is a panic on hostile input, so it will be fixed in its own PR rather than in a behaviour-preserving refactor. ## Breaking changes None. ## Related issues None.
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
research::partition_scanner::scan_partition_bufferlooped offsets up tolen - 3and then checked the two bytes after a matching tag. A tag in the last three bytes followed by a zero byte therefore readbuf[len]and panicked. The loop now ends atlen - 4, and no output changes.Motivation
The helper-refactor review (#1136) found this; that PR left it alone because it was behaviour-preserving. Parsing paths take untrusted input and must not panic (CLAUDE.md). No fuzz target reaches this function.
Changes
src/partition_scanner.rs:let last = buf.len() - 4;. The function already returns early for buffers under 4 bytes, so this cannot underflow. A candidate needs the tag and the two zero bytes after it, so no offset that could yield one is skipped.tests/fuzz_regressions.rs(hardening, run in CI): replays buffers of 4 to 11 bytes that end with an ArcWall tag (0x0191) followed by a zero, on a supported release (2023). Before the fix each one panics, and the test asserts none does.Testing
CI runs the hardening class. The fix is in a research module and changes no export (
scan_partition_bufferserves probes, tests and the ElemTable passthrough).Breaking changes
None.
Related issues
Refs #1136.