fix(mpi): guard MPI byte counts against int overflow - #36
Merged
Merged
Conversation
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.
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 3, MPI). The
intdowncast of a message byte count (repartition'sexchange_vecand the ghostexchange_data) silently wraps negative pastINT_MAX(2 GB), which MPI then rejects or — worse — reads as a bogus length → out-of-boundsmemcpy/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 GBassumption.Both count sites now route through a
mpi_byte_count()helper that throws pastINT_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.