Skip to content

fix(mesh-io): reject invalid dtype and bound header allocations - #35

Merged
nikbott merged 1 commit into
devfrom
fix/mesh-io-reader-robustness
Aug 14, 2026
Merged

nikbott merged 1 commit into
devfrom
fix/mesh-io-reader-robustness

Conversation

@nikbott

@nikbott nikbott commented Aug 14, 2026

Copy link
Copy Markdown
Owner

From the parallel adversarial audit (agent 4, mesh_io):

  • D1: read() treated any field dtype != 1 as float32 — a corrupt/foreign dtype was silently mis-parsed and desynced the stream (every later field became garbage) while read() returned "success". Now rejects dtype ∉ {0,1}.
  • D2: codes/levels/fields/name were resized straight from untrusted header counts, so a hostile n_leaves/n_fields/name_len raised std::bad_alloc/std::length_error (the documented contract is std::runtime_error) and enabled a memory-DoS. Those counts are now bounded against the file size before any allocation.

The engine's own writer only ever emits valid values, so this is pure input-hardening — tests never hit these paths. Adds a [robustness] test (bad dtype, n_leaves = 2^64-1). The MATLAB reader amrIO.m is hardened to match in the code repo.

All CPU suites pass; clang-format + full pre-commit clean.

read() treated any field dtype != 1 as float32, silently mis-parsing and
desyncing the stream on a corrupt/foreign value; it now rejects dtype not in
{0,1}. It also resized codes/levels/fields/name straight from untrusted header
counts, so a hostile n_leaves/n_fields/name_len raised std::bad_alloc or
std::length_error (the contract is std::runtime_error) and enabled a memory-DoS;
those counts are now bounded against the file size first.

Adds a malformed-input test (bad dtype, hostile leaf count).
@nikbott
nikbott merged commit b51dbaa into dev Aug 14, 2026
9 checks passed
@nikbott
nikbott deleted the fix/mesh-io-reader-robustness branch August 22, 2026 16:37
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