Repository navigation
utils: Read SipHash words byte by byte - #47
Open
jasonsopko wants to merge 1 commit into
Open
jasonsopko wants to merge 1 commit into
jasonsopko wants to merge 1 commit into
Conversation
datum_siphash and datum_siphash_mod8 load the key and each message word through a uint64_t cast. The short txn list hashes hash_bin, which sits at offset 178 of T_DATUM_TEMPLATE_TXN, so every word load there is misaligned. x86 tolerates it, but it is undefined behavior, and UBSan stops on it. Read the key and the words with upk_u64le, and build the tail word the same way. Output on little-endian hosts is unchanged. The new test checks the published SipHash-2-4 vectors with the key and message misaligned. On master it fails under UBSan at the key load.
There was a problem hiding this comment.
🟢 Approval recommended
The focused decoding changes preserve SipHash semantics, and regression tests cover misaligned inputs with no unresolved findings.
No open issues 🎉
What changed in this PR
Makes both SipHash implementations safe for unaligned inputs while preserving little-endian results.
Changes:
- Replaces cast-based word loads with
upk_u64le. - Assembles trailing bytes explicitly in little-endian order.
- Adds reference-vector tests with misaligned keys and messages.
| File | Description |
|---|---|
| src/datum_utils.c | Uses alignment-safe, little-endian decoding in both SipHash implementations. |
| src/datum_utils_tests.c | Adds and registers misaligned-input regression tests. |
Review effort: Balanced
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.
What
datum_siphashanddatum_siphash_mod8read the key and the message words withupk_u64leinstead of through auint64_tcast.Why
The short txn list reply (0x90) hashes
hash_bin, which sits at offset 178 ofT_DATUM_TEMPLATE_TXN, so every word load there is misaligned. x86 tolerates it, but it is undefined behavior, and every Linux and FreeBSD CI build has-fsanitize=undefined -fno-sanitize-recover=all. No test sends that request today, so CI is green; the test I suggested on #46 does, and fails under UBSan without this.How I tested
datum_utils.c:694, the key load. With this change it passes in the gcc, clang, Umbrel, no-API and ASan+UBSan configs with-Wall -Werror.datum_siphashand, on the 1,116 messages whose length is a multiple of 8,datum_siphash_mod8.hash_binoffset, best of 200, three runs each: 340.0 to 340.7 us with this change and 339.9 to 341.9 us on master, with the same checksum.Risk and rollback
Output on little-endian hosts is unchanged, and every CI target is little-endian. A big-endian host now reads the words in SipHash's byte order rather than its own. One commit to revert.
Scripts and logs: https://gist.github.com/jasonsopko/7df5dc75053fc4abb65cb7b927c816a8