Skip to content

Commit 12aee90

Browse files
committed
[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
1 parent ca86836 commit 12aee90

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

stdlib/public/RuntimeModule/CompactImageMap.swift

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public enum CompactImageMapFormat {
160160
guard let char = iterator.next() else {
161161
return nil
162162
}
163-
if n > 0 && char == 0x2f {
163+
if base + n > stringBase! && (char == 0x2f || char == 0x5c) {
164164
let prefix = String(decoding: resultBytes[stringBase!..<base+n],
165165
as: UTF8.self)
166166
#if DEBUG_COMPACT_IMAGE_MAP
@@ -297,6 +297,10 @@ public enum CompactImageMapFormat {
297297
let acount = Int(((header >> 3) & 0x7) + 1)
298298
let ecount = Int((header & 0x7) + 1)
299299

300+
#if DEBUG_COMPACT_IMAGE_MAP
301+
print("r = \(relative), acount = \(acount), ecount = \(ecount)")
302+
#endif
303+
300304
// Now the base and end of text addresses
301305
guard let address = decodeAddress(acount) else {
302306
return nil
@@ -315,11 +319,20 @@ public enum CompactImageMapFormat {
315319
}
316320
let endOfText = baseAddress &+ eotOffset
317321

322+
#if DEBUG_COMPACT_IMAGE_MAP
323+
print("address = \(hex(address)), eotOffset = \(hex(eotOffset))")
324+
print("baseAddress = \(hex(baseAddress)), endOfText = \(hex(endOfText))")
325+
#endif
326+
318327
// Next, get the build ID byte count
319328
guard let buildIdBytes = decodeCount() else {
320329
return nil
321330
}
322331

332+
#if DEBUG_COMPACT_IMAGE_MAP
333+
print("buildIdBytes = \(buildIdBytes)")
334+
#endif
335+
323336
// Read the build ID
324337
var buildId: [UInt8]? = nil
325338

@@ -335,6 +348,10 @@ public enum CompactImageMapFormat {
335348
}
336349
}
337350

351+
#if DEBUG_COMPACT_IMAGE_MAP
352+
print("buildId = \(buildId)")
353+
#endif
354+
338355
// Decode the path
339356
let path = decodePath()
340357
let name: String?
@@ -674,6 +691,9 @@ public enum CompactImageMapFormat {
674691

675692
// Add any new prefixes
676693
forEachPrefix(of: remainingPath) { prefix in
694+
#if DEBUG_COMPACT_IMAGE_MAP
695+
print("defining \(nextCode) as \"\(prefix)\"")
696+
#endif
677697
pathPrefixes.append((nextCode, prefix))
678698
nextCode += 1
679699
}

stdlib/public/RuntimeModule/ImageMap.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public struct ImageMap: Collection, Sendable, Hashable {
3333

3434
/// Tells us what size of machine words were used when capturing the
3535
/// image map.
36-
enum WordSize {
36+
enum WordSize: Sendable {
3737
case sixteenBit
3838
case thirtyTwoBit
3939
case sixtyFourBit

0 commit comments

Comments
 (0)