[Backtracing] Fix compact image map decoding bug.

If we ended up with a `/` at the beginning of a string segment, we
were erroneously not adding to the expansion dictionary when we
should have been.

rdar://124913332
This commit is contained in:
Alastair Houghton
2025-01-22 16:35:44 +00:00
parent ca86836133
commit 12aee901c2
2 changed files with 22 additions and 2 deletions

View File

@@ -160,7 +160,7 @@ public enum CompactImageMapFormat {
guard let char = iterator.next() else {
return nil
}
if n > 0 && char == 0x2f {
if base + n > stringBase! && (char == 0x2f || char == 0x5c) {
let prefix = String(decoding: resultBytes[stringBase!..<base+n],
as: UTF8.self)
#if DEBUG_COMPACT_IMAGE_MAP
@@ -297,6 +297,10 @@ public enum CompactImageMapFormat {
let acount = Int(((header >> 3) & 0x7) + 1)
let ecount = Int((header & 0x7) + 1)
#if DEBUG_COMPACT_IMAGE_MAP
print("r = \(relative), acount = \(acount), ecount = \(ecount)")
#endif
// Now the base and end of text addresses
guard let address = decodeAddress(acount) else {
return nil
@@ -315,11 +319,20 @@ public enum CompactImageMapFormat {
}
let endOfText = baseAddress &+ eotOffset
#if DEBUG_COMPACT_IMAGE_MAP
print("address = \(hex(address)), eotOffset = \(hex(eotOffset))")
print("baseAddress = \(hex(baseAddress)), endOfText = \(hex(endOfText))")
#endif
// Next, get the build ID byte count
guard let buildIdBytes = decodeCount() else {
return nil
}
#if DEBUG_COMPACT_IMAGE_MAP
print("buildIdBytes = \(buildIdBytes)")
#endif
// Read the build ID
var buildId: [UInt8]? = nil
@@ -335,6 +348,10 @@ public enum CompactImageMapFormat {
}
}
#if DEBUG_COMPACT_IMAGE_MAP
print("buildId = \(buildId)")
#endif
// Decode the path
let path = decodePath()
let name: String?
@@ -674,6 +691,9 @@ public enum CompactImageMapFormat {
// Add any new prefixes
forEachPrefix(of: remainingPath) { prefix in
#if DEBUG_COMPACT_IMAGE_MAP
print("defining \(nextCode) as \"\(prefix)\"")
#endif
pathPrefixes.append((nextCode, prefix))
nextCode += 1
}