Skip to content

Commit 0d1abf5

Browse files
committed
[SharedCache] Fix crash with cache entries with alignment bytes at the end of the header
We did not truncate the buffer length when reading the header using the mappingOffset size, resulting in a buffer overflow.
1 parent 8c3bd6e commit 0d1abf5

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

view/sharedcache/core/SharedCache.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ CacheEntry CacheEntry::FromFile(const std::string& filePath, const std::string&
6060
// Read the header, this _should_ be compatible with all known DSC formats.
6161
// Mason: the above is not true! https://github.com/Vector35/binaryninja-api/issues/6073
6262
// The mappingOffset should point right after the header. We use this to constrain the read size so unsupported fields are zeroed.
63-
auto headerSize = file->ReadUInt32(0x10);
63+
size_t headerSize = file->ReadUInt32(0x10);
6464
dyld_cache_header header = {};
65-
file->Read(&header, 0, headerSize);
65+
// Truncate buffer length (headerSize) if larger than our `dyld_cache_header` for reading.
66+
file->Read(&header, 0, std::min(headerSize, sizeof(dyld_cache_header)));
6667

6768
// Read the mappings using the headers `mappingCount` and `mappingOffset`.
6869
dyld_cache_mapping_info currentMapping = {};

0 commit comments

Comments
 (0)