Guard string VALUEs while parsing their C string - #556
Merged
Merged
Conversation
StringValueCStr may replace the local VALUE with the result of to_str, leaving the converted String referenced only from a C local. VpAlloc allocates a temporary buffer with rb_str_tmp_new before it scans the C string, so a GC triggered there could free the String while its contents are still being read. Add RB_GC_GUARD after the last use of the pointer in the three places that parse a String argument. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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.
StringValueCStrmay replace the local VALUE with the result ofto_str, leaving the converted String referenced only from a C local.VpAllocallocates a temporary buffer withrb_str_tmp_newbefore it scans the C string, so a GC triggered there could free the String while its contents are still being read.This adds
RB_GC_GUARDafter the last use of the pointer in the three places that parse a String argument:rb_str_convert_to_BigDecimal(BigDecimal(obj)with ato_strobject)BigDecimal_s_interpret_loosely(String#to_d)BigDecimal_loadWith the current compiler output the VALUE happens to stay in a stack slot that the conservative GC scans, so this is not reproducible today, but it depends on register/stack allocation choices rather than on anything guaranteed.
🤖 Generated with Claude Code