Skip to content

Commit

Permalink
Fix unaligned access in LoadStringFromGzip.
Browse files Browse the repository at this point in the history
The code in LoadStringFromGzip was attempting to perform an unaligned
access using memcpy, but it cast the source to a pointer with
alignment requirements larger than 1, which, under optimizations,
reintroduced the original issue.
  • Loading branch information
whitequark committed Jul 18, 2018
1 parent efc3da4 commit 02ec64e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ std::string LoadStringFromGzip(const std::string &name) {

// *(uint32_t *) may perform an unaligned access, so do a memcpy.
uint32_t inflatedSize;
memcpy(&inflatedSize, (uint32_t *)((uintptr_t)data + deflatedSize - 4), sizeof(uint32_t));
memcpy(&inflatedSize, (uint8_t *)((uintptr_t)data + deflatedSize - 4), sizeof(uint32_t));
result.resize(inflatedSize);

stream.next_in = (Bytef *)data;
Expand Down

0 comments on commit 02ec64e

Please sign in to comment.