Skip to content

Commit 1a44883

Browse files
committed
[5.8][Runtime] Fix key paths on 32-bit with KVC string pointers in the top half of memory.
Key paths can store an offset or a pointer in the same field. On 32-bit, the field is considered to be an offset when it's less than the 4kB zero page, and a pointer otherwise. The check uses a signed comparison, so pointers in the top half of memory would look like negative offsets. Add a check that the offset is zero or positive to avoid this. rdar://103886537 (cherry picked from commit 1f8acac)
1 parent 0adeb61 commit 1a44883

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

stdlib/public/core/KeyPath.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ public class AnyKeyPath: Hashable, _AppendKeyPath {
177177
}
178178
else {
179179
let offset = Int(bitPattern: _kvcKeyPathStringPtr) - 1
180-
if (offset <= maximumOffsetOn32BitArchitecture) {
180+
// Pointers above 0x7fffffff will come in as negative numbers which are
181+
// less than maximumOffsetOn32BitArchitecture, be sure to reject them.
182+
if (offset >= 0 && offset <= maximumOffsetOn32BitArchitecture) {
181183
return offset
182184
}
183185
return nil

0 commit comments

Comments
 (0)