Repository navigation
Fix buffer overflow in chilled string warning in String#setbyte - #19913
Merged
peterzhu2118 merged 1 commit intoNov 16, 2026
Merged
Conversation
If the source string is modified in the chilled string warning in String#setbyte,
it will cause a buffer overflow because the string length is read before
the warning.
For example, the following code will output an error in ASAN:
Warning[:deprecated] = true
module Warning
def self.warn(msg, **kw) = $s.clear
end
# 1000-byte chilled literal (heap allocated)
eval("$s = '#{"a" * 1000}'")
$s.setbyte(999, 0x42)
p $s
Outputs:
ERROR: AddressSanitizer: use-after-poison on address 0x0001235e44d7 at pc 0x0001027170d4 bp 0x00016dc48f50 sp 0x00016dc48f48
WRITE of size 1 at 0x0001235e44d7 thread T0
#0 0x0001027170d0 in rb_str_setbyte string.c:7405
#1 0x0001028756a4 in vm_call_cfunc_with_frame_ vm_insnhelper.c:3936
ruby#2 0x000102860918 in vm_call_method_each_type vm_insnhelper.c:5041
ruby#3 0x00010285ffd4 in vm_call_method vm_insnhelper.c
ruby#4 0x00010281de04 in vm_sendish vm_insnhelper.c:6429
ruby#5 0x00010281de04 in vm_exec_core insns.def:912
ruby#6 0x000102809388 in rb_vm_exec vm.c:2917
ruby#7 0x0001023a0400 in rb_ec_exec_node eval.c:300
ruby#8 0x0001023a0228 in ruby_run_node eval.c:338
ruby#9 0x0001021b4c20 in rb_main main.c:42
ruby#10 0x0001021b4c20 in main main.c:62
ruby#11 0x0001916bcd78 in start+0x19f8 (dyld:arm64e+0x31d78)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If the source string is modified in the chilled string warning in String#setbyte, it will cause a buffer overflow because the string length is read before the warning.
For example, the following code will output an error in ASAN:
Outputs: