Skip to content

Various UB fixes and Code Improvements - #318

Merged
phip1611 merged 4 commits into
mainfrom
ub1
Sep 2, 2026
Merged

Various UB fixes and Code Improvements#318
phip1611 merged 4 commits into
mainfrom
ub1

Conversation

@phip1611

@phip1611 phip1611 commented Sep 2, 2026

Copy link
Copy Markdown
Member

Fix various UB, identified with claude/fable

All other dst_len implementations assert that the reported tag size
covers the base size before subtracting; NetworkTag was the only one
missing this guard.
@phip1611 phip1611 self-assigned this Sep 2, 2026
The string table is not part of the tag: the tag only stores the
physical address (sh_addr) and size of the section holding it, both
taken verbatim from the boot information.

Make the function unsafe and document the caller's obligations.
All other dst_len implementations assert that the reported tag size
covers the base size before subtracting; this one was missing the
guard.
Both traits carry soundness-critical contracts that safe code could
violate: ref_from_bytes/ref_from_slice materialize &H from raw bytes
(a Header type with a niche, e.g. a NonZeroU32 field, leads to an
invalid value), and cast/new_boxed derive reference extents from
BASE_SIZE/dst_len (a wrong dst_len creates a reference beyond the
allocation). Miri confirms both as undefined behavior with purely safe
downstream impls.
@phip1611
phip1611 enabled auto-merge September 2, 2026 12:16
@phip1611
phip1611 added this pull request to the merge queue Sep 2, 2026
Merged via the queue into main with commit b909f04 Sep 2, 2026
29 checks passed
@phip1611
phip1611 deleted the ub1 branch September 2, 2026 12:23
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