Commit 7dfd560
mruby-io: cap puts recursion depth to prevent C stack overflow
io_puts_ary recursed unconditionally on nested arrays. For cyclic
arrays (a = []; a << a; puts a) or pathologically deep arrays,
this caused a C stack overflow.
Add a depth cap (IO_PUTS_MAX_DEPTH = 16); on overflow, write
"[...]\n" and return, matching CRuby's behavior on cycles. The
pattern mirrors mruby-set's MAX_NESTED_DEPTH for the same problem
shape (pure C recursion not dispatched as a Ruby method).
Reported by OSS-Fuzz (clusterfuzz testcase 6233530857488384).
Co-authored-by: Claude <[email protected]>1 parent 8a73faf commit 7dfd560
1 file changed
Lines changed: 13 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
992 | 992 | | |
993 | 993 | | |
994 | 994 | | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
995 | 999 | | |
996 | 1000 | | |
997 | | - | |
| 1001 | + | |
998 | 1002 | | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
999 | 1009 | | |
1000 | 1010 | | |
1001 | 1011 | | |
| |||
1008 | 1018 | | |
1009 | 1019 | | |
1010 | 1020 | | |
1011 | | - | |
| 1021 | + | |
1012 | 1022 | | |
1013 | 1023 | | |
1014 | 1024 | | |
| |||
1040 | 1050 | | |
1041 | 1051 | | |
1042 | 1052 | | |
1043 | | - | |
| 1053 | + | |
1044 | 1054 | | |
1045 | 1055 | | |
1046 | 1056 | | |
| |||
0 commit comments