Actions
Bug #15941
closedIssue with String#scrub when given block and receiver is modified in block
    Bug #15941:
    Issue with String#scrub when given block and receiver is modified in block
  
Description
This should cause a segmentation fault:
s = "abc\u3042\xE3\x80"
loop do
    s.scrub{|bytes| s << "more content"; "?" }
end
Not something that should happen, but I thought it might cause undesired behavior.
Thank you for your time :)
Files
        
          
          Updated by luke-gru (Luke Gruber) over 6 years ago
          
          
        
        
      
      I guess the solution here would be something similar to String#gsub, with str_mod_check.
        
          
          Updated by jeremyevans0 (Jeremy Evans) over 6 years ago
          
          
        
        
      
      - File scrub-modify-check.patch scrub-modify-check.patch added
 
I can confirm this issue, and agree that handling it similarly to String#gsub makes sense.  Attached is a patch that does that.
        
          
          Updated by luke-gru (Luke Gruber) over 6 years ago
          
          
        
        
      
      Patch lgtm, thanks!
        
          
          Updated by jeremyevans (Jeremy Evans) over 6 years ago
          
          
        
        
      
      - Status changed from Open to Closed
 
Applied in changeset git|0f283054e7f568f09fbfc952d57ea6daf4abbd88.
Check that String#scrub block does not modify receiver
Similar to the check used for String#gsub.  Can fix possible
segfault.
Fixes [Bug #15941]
Actions