Commit 3b13a4f
authored
Fix unsigned integer overflow in binary plist offset-table bounds check (#596)
* Fix unsigned integer overflow in binary plist offset-table bounds check
* Source/NSPropertyList.m: Reformulate the offset-table sanity check
in GSBinaryPLParser -initWithData:mutability: to avoid unsigned
integer overflow in the multiplication. The prior form
`table_start + object_count * offset_size > _length` overflows on
32-bit unsigned whenever object_count * offset_size crosses 2^32;
with offset_size already bounded to 1..4 by the guard above, an
attacker-controlled object_count near 2^30 wraps the product past
2^32 and lets a malformed trailer slip through, after which
-offsetForIndex: reads past _bytes. Rewritten as
`table_start > _length || object_count > (_length - table_start)
/ offset_size` which never forms the product and keeps the
subtraction from underflowing at the check site, so correctness
no longer depends on the ordering of sibling branches.
* Tests/base/NSPropertyList/TestInfo: New test group marker.
* Tests/base/NSPropertyList/bplist-overflow-bounds.m: New regression
test. Four assertions: two positive-control round-trips of a
legitimately serialized bplist, plus two crafted trailers with
object_count=0x40000000 and 0xffffffff against offset_size=4 that
wrap the pre-fix product and would have been accepted. Written in
plain main() with conditions inline in PASS(); uses NS_DURING only
around the parser call itself because the bplist branch of
+propertyListWithData:options:format:error: raises NSException on
malformed input rather than populating the error out-parameter.
Validated on Ubuntu 24.04 with clang 18 + libobjc2. With the fix
applied, all 4 assertions pass. With the source change reverted but
the test left in place, the 2 overflow-attack assertions fail (the
pre-fix sum check accepts both wrapped trailers) while both
positive-control assertions still pass, confirming each assertion
actually discriminates the fixed and unfixed builds.
* Apply review feedback from PR #596
* Source/NSPropertyList.m: Shorten the block comment above the
rewritten bounds check to a note about the unsigned-overflow
hazard and a pointer to the regression test.
* Tests/base/NSPropertyList/bplist-overflow-bounds.m: Use
PASS_EXCEPTION(NSGenericException) instead of hand-rolled
NS_DURING/NS_HANDLER around the parser call, and PASS_EQUAL for
the positive-control round-trip. PASS already catches stray
exceptions, so neither helper function needs a try/catch wrapper.
No change to the fix itself. Re-validated on Ubuntu 24.04 +
clang 18: 4/4 pass with fix, 2/4 pass without (both overflow
attacks fail as designed, both positive controls still pass).1 parent 8d5bc8f commit 3b13a4f
4 files changed
Lines changed: 170 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
1 | 24 | | |
2 | 25 | | |
3 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3085 | 3085 | | |
3086 | 3086 | | |
3087 | 3087 | | |
3088 | | - | |
| 3088 | + | |
| 3089 | + | |
| 3090 | + | |
| 3091 | + | |
| 3092 | + | |
| 3093 | + | |
| 3094 | + | |
3089 | 3095 | | |
3090 | 3096 | | |
3091 | 3097 | | |
| |||
Whitespace-only changes.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
0 commit comments