Skip to content

Commit 9aac812

Browse files
committed
[Backtracing] Fix a few niggles.
It turns out that .copyBytes() checks that the source doesn't provide more bytes than the destination will accept. rdar://117681625
1 parent d0b788a commit 9aac812

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

stdlib/public/Backtracing/ArrayImageSource.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct ArrayImageSource<T>: ImageSource {
4242
throw ArrayImageSourceError.outOfBoundsRead(addr, requested)
4343
}
4444

45-
buffer.copyBytes(from: $0[Int(addr)...])
45+
buffer.copyBytes(from: $0[Int(addr)..<Int(addr+requested)])
4646
}
4747
}
4848
}

stdlib/public/Backtracing/CachingMemoryReader.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public class CachingMemoryReader<T: MemoryReader>: MemoryReader {
7575
let maxBytes = pageSize - offset
7676
let chunk = min(remaining, maxBytes)
7777

78-
buffer[done..<done+chunk].copyBytes(from: page[offset...])
78+
buffer[done..<done+chunk].copyBytes(from: page[offset..<offset+chunk])
7979

8080
offset = 0
8181
done += chunk

stdlib/public/Backtracing/MemoryReader.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ extension MemoryReader {
245245
throw MemserverError(message: "Unreadable at \(hex(addr))")
246246
}
247247

248-
if done + Int(reply.len) > bytes.count {
249-
throw MemserverError(message: "Overrun at \(hex(addr)) trying to read \(bytes.count) bytes")
248+
if buffer.count - done < Int(reply.len) {
249+
throw MemserverError(message: "Overrun at \(hex(addr)) trying to read \(buffer.count) bytes")
250250
}
251251

252252
let ret = try safeRead(fd,

0 commit comments

Comments
 (0)