Skip to content

fix(mpi): guard MPI byte counts against int overflow - #36

Merged
nikbott merged 1 commit into
devfrom
fix/mpi-count-overflow-guard
Aug 14, 2026
Merged

nikbott merged 1 commit into
devfrom
fix/mpi-count-overflow-guard

Conversation

@nikbott

@nikbott nikbott commented Aug 14, 2026

Copy link
Copy Markdown
Owner

From the parallel adversarial audit (agent 3, MPI). The int downcast of a message byte count (repartition's exchange_vec and the ghost exchange_data) silently wraps negative past INT_MAX (2 GB), which MPI then rejects or — worse — reads as a bogus length → out-of-bounds memcpy/wire corruption. Reachable only at ~billion-leaf scale (≥268 M leaves per pairwise message), invisible to the np=2/4 test meshes, and the code even commented the unenforced <2 GB assumption.

Both count sites now route through a mpi_byte_count() helper that throws past INT_MAX — a clear failure instead of silent corruption. (A full fix — derived MPI datatypes with element counts, or chunking — is larger and unnecessary at DIC scales; the guard makes the limit explicit and safe.)

MPI suite passes at np=2/4; clang-format + pre-commit clean.

The int downcast of a message byte count silently wraps negative past
INT_MAX (2 GB), which MPI then rejects or, worse, reads as a bogus length ->
out-of-bounds/wire corruption. Reachable only at billion-leaf scale, but a
silent corruption there is far worse than a clear error. Route both
count sites (repartition, ghost exchange) through a mpi_byte_count() that
throws past INT_MAX.
@nikbott
nikbott merged commit 52e07cb into dev Aug 14, 2026
9 checks passed
@nikbott
nikbott deleted the fix/mpi-count-overflow-guard branch August 14, 2026 14:07
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