Repository navigation
Fix misaligned uint32_t load of dex map_list.size - #2249
Merged
plusvic merged 2 commits intoOct 15, 2026
Merged
Conversation
map_offset comes straight from the DEX file and is never alignment checked, but the map list size was read by casting dex->data + map_offset to uint32_t* and dereferencing. Any file whose map_offset is not a multiple of 4 is undefined behavior. UBSan reports: libyara/modules/dex/dex.c:1163:5: runtime error: load of misaligned address 0x... for type 'uint32_t', which requires 4 byte alignment Read the size through memcpy instead. This is the only bare (uint32_t*) cast-deref in the module; every other structure access goes through the pragma pack(1) types, whose member loads tolerate any alignment. No behavior change: same bytes, same yr_le32toh conversion, same bounds checks.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Author
|
@google-cla bot check |
plusvic
approved these changes
Oct 15, 2026
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.
The map list size was read by casting
dex->data + map_offsettouint32_t*and dereferencing, butmap_offsetcomes straight from the DEX header and is never alignment checked, so any file whosemap_offsetis not a multiple of 4 is undefined behavior. Found with an ASan+UBSan build fuzzing the dex module overtests/oss-fuzz/dex_fuzzer_corpus; UBSan reports the load at dex.c:1163 and 1165, and the loop bound at 1171 reads the same pointer:A 160-byte DEX with
map_offset = 5reproduces it deterministically:The size is now read through
memcpyinto a local withyr_le32tohapplied once, which also collapses the repeatedyr_le32toh(*map_list_size)in the loop bound. This is the only bare(uint32_t*)cast-deref in the module; every other structure access goes through the#pragma pack(1)types inyara/dex.h, whose member loads tolerate any alignment. Same bytes, same endian conversion, samefits_in_dexbounds checks, so no behavior change: the reproducer is UBSan-silent after the fix and every file intests/oss-fuzz/dex_fuzzer_corpusstill parses.