Commit af6f23d
mruby-string-ext: fix String#prepend with self-referencing arguments
String#prepend(s, s) read RSTRING_LEN(argv[i]) in the copy loop after
mrb_str_resize had already updated the receiver's length, causing the
memcpy to write past the allocated buffer.
Detect self-references with mrb_obj_eq() and read from the memmoved
original data at p + total_prepend_len using the captured self_len.
This also handles mixed cases like s.prepend("X", s) where earlier
writes would otherwise corrupt the source of later reads.
Co-authored-by: Claude <noreply@anthropic.com>1 parent 4eb4884 commit af6f23d
2 files changed
+30
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2201 | 2201 | | |
2202 | 2202 | | |
2203 | 2203 | | |
2204 | | - | |
| 2204 | + | |
| 2205 | + | |
| 2206 | + | |
| 2207 | + | |
2205 | 2208 | | |
2206 | 2209 | | |
2207 | 2210 | | |
2208 | 2211 | | |
2209 | 2212 | | |
2210 | | - | |
| 2213 | + | |
| 2214 | + | |
| 2215 | + | |
| 2216 | + | |
| 2217 | + | |
| 2218 | + | |
| 2219 | + | |
| 2220 | + | |
| 2221 | + | |
| 2222 | + | |
2211 | 2223 | | |
2212 | | - | |
| 2224 | + | |
2213 | 2225 | | |
2214 | 2226 | | |
2215 | 2227 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
492 | 492 | | |
493 | 493 | | |
494 | 494 | | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
495 | 510 | | |
496 | 511 | | |
497 | 512 | | |
| |||
0 commit comments