Repository navigation
Commit 28ba1e3
Fix use-after-free when packing a string into an IO
msgpack_buffer_append_string read the string's raw pointer up front and
then grew the buffer. Growing it runs io.write (arbitrary Ruby) and can
trigger GC, either of which may free or shrink the string's backing
memory, so the later memcpy could read freed memory and copy heap
contents into the output. Reserve the space first and read the pointer
only afterwards, clamping and zero-filling if the string shrank in the
meantime so the copy stays within the current buffer.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent 314d65d commit 28ba1e3
1 file changed
Lines changed: 19 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
237 | 237 | | |
238 | 238 | | |
239 | 239 | | |
240 | | - | |
241 | | - | |
242 | | - | |
| 240 | + | |
243 | 241 | | |
244 | 242 | | |
245 | 243 | | |
246 | 244 | | |
247 | | - | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
248 | 263 | | |
249 | 264 | | |
250 | 265 | | |
| |||
0 commit comments