Commit 076d09e
committed
Fix GH-22678: array_multisort() use-after-free on mutating comparator
array_multisort() snapshotted each input array's buckets without holding a
reference, then ran a comparator that under SORT_STRING invokes
Stringable::__toString(); a callback that unset or reassigned the array freed
its backing store and elements mid-sort, a use-after-free read in the
comparator and a write-back through the freed table during the restructure.
Hold a reference on each input HashTable for the duration of the sort and
restructure the cached tables, mirroring zend_array_sort_ex() (GH-16648).
HT_ALLOW_COW_VIOLATION allows the in-place repack under the held reference.
Fixes GH-226781 parent 8b1079a commit 076d09e
3 files changed
Lines changed: 71 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| 88 | + | |
| 89 | + | |
88 | 90 | | |
89 | 91 | | |
90 | 92 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6046 | 6046 | | |
6047 | 6047 | | |
6048 | 6048 | | |
| 6049 | + | |
6049 | 6050 | | |
6050 | 6051 | | |
6051 | 6052 | | |
| |||
6167 | 6168 | | |
6168 | 6169 | | |
6169 | 6170 | | |
| 6171 | + | |
| 6172 | + | |
| 6173 | + | |
| 6174 | + | |
| 6175 | + | |
| 6176 | + | |
6170 | 6177 | | |
6171 | 6178 | | |
6172 | | - | |
6173 | | - | |
6174 | | - | |
| 6179 | + | |
| 6180 | + | |
| 6181 | + | |
6175 | 6182 | | |
6176 | 6183 | | |
6177 | 6184 | | |
6178 | 6185 | | |
6179 | 6186 | | |
6180 | 6187 | | |
6181 | 6188 | | |
6182 | | - | |
6183 | | - | |
| 6189 | + | |
| 6190 | + | |
6184 | 6191 | | |
6185 | 6192 | | |
6186 | 6193 | | |
| |||
6200 | 6207 | | |
6201 | 6208 | | |
6202 | 6209 | | |
6203 | | - | |
| 6210 | + | |
6204 | 6211 | | |
6205 | 6212 | | |
6206 | 6213 | | |
| |||
6229 | 6236 | | |
6230 | 6237 | | |
6231 | 6238 | | |
| 6239 | + | |
| 6240 | + | |
| 6241 | + | |
| 6242 | + | |
| 6243 | + | |
| 6244 | + | |
| 6245 | + | |
| 6246 | + | |
6232 | 6247 | | |
6233 | 6248 | | |
6234 | 6249 | | |
| |||
| 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 | + | |
0 commit comments