Commit 51751f0
committed
Fix heap buffer overflow in UTF-16 encoder via error handler rewind
When encoding UTF-16 and a user-supplied error handler rewinds the
position (newpos < pos), the resize calculation counted characters
instead of UTF-16 code units. Supplementary characters (>= U+10000)
each need 2 UTF-16 units but were counted as 1, causing an undersized
buffer allocation. The subsequent re-encoding pass would overflow the
buffer by 2 bytes per supplementary character in the rewind range.
Fix by counting actual UTF-16 code units needed: for UCS-4 kind
strings, add an extra unit for each supplementary character in the
rewind range.
https://claude.ai/code/session_01XLyeaYE4CLWT5QPZYR3KDr1 parent 300de1e commit 51751f0
1 file changed
Lines changed: 14 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6387 | 6387 | | |
6388 | 6388 | | |
6389 | 6389 | | |
6390 | | - | |
| 6390 | + | |
| 6391 | + | |
| 6392 | + | |
| 6393 | + | |
| 6394 | + | |
| 6395 | + | |
| 6396 | + | |
| 6397 | + | |
| 6398 | + | |
| 6399 | + | |
| 6400 | + | |
| 6401 | + | |
| 6402 | + | |
| 6403 | + | |
6391 | 6404 | | |
6392 | 6405 | | |
6393 | 6406 | | |
| |||
0 commit comments