Conversation
phip1611
force-pushed
the
ub
branch
2 times, most recently
from
September 2, 2026 11:41
bb67996 to
a1c1d41
Compare
phip1611
commented
Sep 2, 2026
phip1611
enabled auto-merge
September 2, 2026 13:20
phip1611
disabled auto-merge
September 2, 2026 13:21
MaybeDynSized::as_bytes previously covered size_of_val(self) bytes and thus included the implicit trailing padding that the Rust memory layout adds beyond the structure size reported in the header. For stack-constructed sized tags, that padding is uninitialized memory, so reading the returned slice was undefined behavior (caught by Miri). Zeroing the padding in the constructors is no fix: the language resets padding bytes to uninitialized on every typed copy, including returning the value from the constructor. Instead, as_bytes now returns a plain byte slice covering exactly the reported structure size, clamped to the allocation, so uninitialized padding is never exposed. The tag alignment in the built structures previously came from the padded as_bytes slices. Both builders now serialize their tags into a byte buffer and fill it with explicit zeroes up to the next 8-byte boundary after each tag, as mandated by the Multiboot2 spec. The built structures are byte-wise identical, except that the inter-tag padding is now guaranteed to be zeroed instead of copied from uninitialized memory.
As a side effect of the previous commit, payload() and therefore clone_dyn() now operate on the exact payload: cloning a DST whose size is no multiple of the alignment previously grew the reported size to the padded allocation size; now the size round-trips exactly. Lock this in with a test using a payload whose tag size is no multiple of the alignment.
…ytes Regression test for the uninitialized-padding fixes: reading every byte of the built MBI is defined behavior only if all serialized tags are fully initialized. Miri catches any regression.
Regression test for the uninitialized-padding fixes: reading every byte of the built header is defined behavior only if all serialized tags are fully initialized. Miri catches any regression.
One representative test for all stack-constructed sized tags with implicit trailing padding: the constructor plus as_bytes() must expose exactly the reported tag size and only initialized bytes. Miri verifies the absence of undefined behavior. ApmTag is the tag with the most fields and the largest gap between spec size (28) and Rust type size (32).
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.
No description provided.