Fix undefined behavior in deserialize_header()#31
Merged
sethatwood merged 2 commits intobitcoinecho:mainfrom Jan 7, 2026
Merged
Conversation
Move deserialize_u32/64_le and serialize_u32/64_le implementations from serialize.c to serialize.h as static inline functions. These tiny helpers benefit from inlining to avoid function call overhead on hot paths during block sync. Co-authored-by: JesterHodl <jesterhodl@jesterhodl.com>
bdd5601 to
3c7c933
Compare
Member
|
Thanks for this contribution! The UB fix and consolidation are exactly right. We added one small refinement on top: making the helpers Appreciate you catching the UBSan issue and taking the initiative to clean up the duplication! |
sethatwood
added a commit
that referenced
this pull request
Jan 7, 2026
This attempts to fix #30 by: - consolidating `read_u32_le()`, `read_u64_le()`, `write_u32_le()`, `write_u64_le()` - renames them to `deserialize`/`serialize` to avoid conflicts with `protocol/serialize.c` functions with the same name, but different type and signature - removes UBSan bug from `deserialize_header()` by using `deserialize_u32_le()` --------- Co-authored-by: Seth Atwood <sethmerrick@gmail.com>
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.
This attempts to fix #30 by:
read_u32_le(),read_u64_le(),write_u32_le(),write_u64_le()deserialize/serializeto avoid conflicts withprotocol/serialize.cfunctions with the same name, but different type and signaturedeserialize_header()by usingdeserialize_u32_le()