Skip to content

Read 16-bit packet fields with memcpy - #1433

Closed
zgiles wants to merge 1 commit into
mobile-shell:masterfrom
zgiles:harden/unaligned-reads
Closed

zgiles wants to merge 1 commit into
mobile-shell:masterfrom
zgiles:harden/unaligned-reads

Conversation

@zgiles

@zgiles zgiles commented Oct 22, 2026

Copy link
Copy Markdown

Casting char* to uint16_t* is a strict-aliasing violation and an unaligned load, which faults on ARM/SPARC. The reads now use memcpy, matching the 64-bit read next to them.

Packet::Packet and Fragment::Fragment read 16-bit header fields by casting the
input string's char storage to uint16_t* and indexing it. That is a strict-
aliasing violation (undefined behavior the optimizer may miscompile) and an
unaligned load that faults on strict-alignment architectures such as ARM and
SPARC. The adjacent 64-bit id read already used memcpy; this makes the 16-bit
reads consistent. Behavior is byte-for-byte identical (cppcheck dangerousTypeCast).
@achernya achernya closed this Oct 22, 2026
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.

2 participants