summaryrefslogtreecommitdiff
path: root/view/sharedcache/core
diff options
context:
space:
mode:
authorMason Reed <mason@vector35.com>2025-04-14 21:25:58 -0400
committerMason Reed <mason@vector35.com>2025-04-14 21:25:58 -0400
commit0d1abf5f01797a22e28360767fb3ac86576104f5 (patch)
tree2c35ac48b80673d1cb9204c08fcaa36e6f6c3853 /view/sharedcache/core
parent8c3bd6e14eafe4b1d0af509c7abc7e6bd9a97c15 (diff)
[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.
Diffstat (limited to 'view/sharedcache/core')
-rw-r--r--view/sharedcache/core/SharedCache.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/view/sharedcache/core/SharedCache.cpp b/view/sharedcache/core/SharedCache.cpp
index 4950c8c0..66c737d0 100644
--- a/view/sharedcache/core/SharedCache.cpp
+++ b/view/sharedcache/core/SharedCache.cpp
@@ -60,9 +60,10 @@ CacheEntry CacheEntry::FromFile(const std::string& filePath, const std::string&
// Read the header, this _should_ be compatible with all known DSC formats.
// Mason: the above is not true! https://github.com/Vector35/binaryninja-api/issues/6073
// The mappingOffset should point right after the header. We use this to constrain the read size so unsupported fields are zeroed.
- auto headerSize = file->ReadUInt32(0x10);
+ size_t headerSize = file->ReadUInt32(0x10);
dyld_cache_header header = {};
- file->Read(&header, 0, headerSize);
+ // Truncate buffer length (headerSize) if larger than our `dyld_cache_header` for reading.
+ file->Read(&header, 0, std::min(headerSize, sizeof(dyld_cache_header)));
// Read the mappings using the headers `mappingCount` and `mappingOffset`.
dyld_cache_mapping_info currentMapping = {};