fix(mesh-io): reject invalid dtype and bound header allocations - #35
Merged
Merged
Conversation
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).
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.
From the parallel adversarial audit (agent 4, mesh_io):
read()treated any fielddtype != 1as float32 — a corrupt/foreigndtypewas silently mis-parsed and desynced the stream (every later field became garbage) whileread()returned "success". Now rejectsdtype ∉ {0,1}.codes/levels/fields/namewere resized straight from untrusted header counts, so a hostilen_leaves/n_fields/name_lenraisedstd::bad_alloc/std::length_error(the documented contract isstd::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 readeramrIO.mis hardened to match in the code repo.All CPU suites pass; clang-format + full pre-commit clean.