Skip to content

Commit c925399

Browse files
droeemesare
andcommitted
[SharedCache] Avoid reading header fields outside of the bounds of the header
Use mappingOffset as an upper bound for the header size, and avoid reading any header fields from beyond that offset. Co-authored-by: Mason Reed <[email protected]>
1 parent ee11cbb commit c925399

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

view/sharedcache/core/SharedCacheView.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,6 @@ bool SharedCacheView::Init()
175175

176176
m_logger = new Logger("SharedCache.View", GetFile()->GetSessionId());
177177

178-
uint32_t platform;
179-
// NOTE: This entry only exists on ios 11 and later, older versions will just assume iOS.
180-
GetParentView()->Read(&platform, 0xd8, 4);
181178
char magic[17];
182179
GetParentView()->Read(&magic, 0, 16);
183180
magic[16] = 0;
@@ -197,8 +194,19 @@ bool SharedCacheView::Init()
197194
return false;
198195
}
199196

200-
// TODO: Do we want to add any warnings about platform support here?
201-
// TODO: Do we still consider macos experimental?
197+
// Use the value of mappingOffset as an upper bound for the size of the
198+
// header to avoid misinterpreting bytes outside of the header.
199+
uint32_t mappingOffset;
200+
GetParentView()->Read(&mappingOffset, 0x10, 4);
201+
202+
uint32_t platform;
203+
if (mappingOffset >= 0xd8 + 4) {
204+
GetParentView()->Read(&platform, 0xd8, 4);
205+
} else {
206+
m_logger->LogWarn("Old header without platform field: Defaulting to iOS");
207+
platform = DSCPlatformiOS;
208+
}
209+
202210
switch (platform)
203211
{
204212
case DSCPlatformMacOS:
@@ -219,9 +227,8 @@ bool SharedCacheView::Init()
219227
m_logger->LogError("Unsupported platform: %d", platform);
220228
return false;
221229
default:
222-
m_logger->LogWarn("Unknown platform: %d selecting iOS...", platform);
223-
os = "ios";
224-
break;
230+
m_logger->LogWarn("Unknown platform: %d", platform);
231+
return false;
225232
}
226233

227234
SetDefaultPlatform(Platform::GetByName(os + "-" + arch));

0 commit comments

Comments
 (0)