Loading...
common/ProcessAtlas.cpp dyld-1066.8 dyld-1162
--- dyld/dyld-1066.8/common/ProcessAtlas.cpp
+++ dyld/dyld-1162/common/ProcessAtlas.cpp
@@ -24,6 +24,8 @@
 
 #include <TargetConditionals.h>
 
+#if !TARGET_OS_EXCLAVEKIT
+
 #include <atomic>
 #include <cstring>
 #include <Block.h>
@@ -39,8 +41,8 @@
 #include <sys/stat.h>
 #include <sys/fsgetpath.h>
 
+#include <mach/mach_time.h> // mach_absolute_time()
 #include <mach/mach_vm.h>
-#include <mach/mach_time.h> // mach_absolute_time()
 #include <mach-o/dyld_priv.h> // FIXME: We can remove this once we fully integrate into dyld4
 #include "dyld_cache_format.h"
 //FIXME: We should remove this header
@@ -588,9 +590,9 @@
 #if BUILDING_DYLD
 Image::Image(RuntimeState* state, Allocator& ephemeralAllocator, SharedPtr<Mapper>& mapper, const Loader* ldr)
     :   _ephemeralAllocator(ephemeralAllocator), _mapper(mapper), _rebasedAddress((void*)ldr->loadAddress(*state)) {
-        auto fileID = ldr->fileID(state->fileManager);
+        auto fileID = ldr->fileID(*state);
         if (fileID.inode() &&  fileID.device()) {
-            _file = state->fileManager.fileRecordForFileID(ldr->fileID(state->fileManager));
+            _file = state->fileManager.fileRecordForFileID(ldr->fileID(*state));
             if ( _file.volume().empty() ) {
                 _file = state->fileManager.fileRecordForPath(ephemeralAllocator, ldr->path());
             }
@@ -1886,7 +1888,7 @@
     }
 }
 
-void ProcessSnapshot::Serializer::readMappedFileInfo(std::span<std::byte>& data, uint64_t& rebasedAddress, UUID& uuid, FileRecord& file) {
+bool ProcessSnapshot::Serializer::readMappedFileInfo(std::span<std::byte>& data, uint64_t& rebasedAddress, UUID& uuid, FileRecord& file) {
     uint64_t flags = readPVLEUInt64(data);
     rebasedAddress = readPVLEUInt64(data);
     if (flags & kMappedFileFlagsHasUUID) {
@@ -1896,12 +1898,17 @@
     if (flags & kMappedFileFlagsHasFileID) {
         uint64_t volumeIndex = readPVLEUInt64(data);
         uint64_t objectID = readPVLEUInt64(data);
+        if (volumeIndex >= _volumeUUIDs.size() )
+            return false;
         file = _fileManager.fileRecordForVolumeUUIDAndObjID(_volumeUUIDs[(size_t)volumeIndex], objectID);
     }
     if (flags & kMappedFileFlagsHasFilePath) {
         uint64_t pathOffset = readPVLEUInt64(data);
+        if ( pathOffset >= _stringTableBuffer.size() )
+            return false;
         file = _fileManager.fileRecordForPath(_ephemeralAllocator, &_stringTableBuffer[(size_t)pathOffset]);
     }
+    return true;
 }
 
 Vector<std::byte> ProcessSnapshot::Serializer::serialize() {
@@ -2005,17 +2012,17 @@
     _timestamp          = read<uint64_t>(i);
     _crc32c             = read<uint32_t>(i);
     if (_magic != kMagic) {
-        assert(0);
+        return false;
     }
     if (_version != 0) {
-        assert(0);
+        return false;
     }
     CRC32c checksumer;
     checksumer(std::span(&data[0], 32));
     checksumer((uint32_t)0); // Zero out the actual checksum
     checksumer(std::span(&data[36], data.size() - 36));
     if (_crc32c != checksumer) {
-        assert(0);
+        return false;
     }
     _processFlags           = readPVLEUInt64(i);
     _platform               = readPVLEUInt64(i);
@@ -2036,7 +2043,8 @@
         uint64_t rebasedAddress;
         UUID uuid;
         FileRecord file;
-        readMappedFileInfo(i, rebasedAddress, uuid, file);
+        if ( !readMappedFileInfo(i, rebasedAddress, uuid, file) )
+            return false;
         rebasedAddress = rebasedAddress * ((_processFlags & kProcessFlagsHas16kPages) ? 16384 : 4096);
         SharedPtr<Mapper> mapper = nullptr;
         if (_processSnapshot._useIdentityMapper) {
@@ -2062,7 +2070,8 @@
         uint64_t rebasedAddress;
         UUID uuid;
         FileRecord file;
-        readMappedFileInfo(i, rebasedAddress, uuid, file);
+        if ( !readMappedFileInfo(i, rebasedAddress, uuid, file) )
+            return false;
         rebasedAddress = (rebasedAddress * ((_processFlags & kProcessFlagsHas16kPages) ? 16384 : 4096)) + lastAddress;
         lastAddress = rebasedAddress;
         SharedPtr<Mapper> mapper = nullptr;
@@ -2082,3 +2091,4 @@
 
 };
 };
+#endif // !TARGET_OS_EXCLAVEKIT