Commit 06eda50
committed
Fix integer overflow in the JSON scanner string length adjustments
The scanner accumulates escape shrinkage and invalid-UTF-8 adjustment in
int fields, so a string carrying more than 2^31 escape sequences or
ignored invalid bytes wraps the counter and makes the first pass reserve
a result several gigabytes longer than the second pass writes.
json_decode() of a 2 GiB run of invalid bytes with
JSON_INVALID_UTF8_IGNORE returns a 4 GiB string instead of an empty one.
Widen both counters to ptrdiff_t, which is what the token length they
adjust is already measured in.
Closes GH-229201 parent 5226e2f commit 06eda50
2 files changed
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
295 | 295 | | |
296 | 296 | | |
297 | 297 | | |
298 | | - | |
| 298 | + | |
299 | 299 | | |
300 | 300 | | |
301 | 301 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| |||
0 commit comments