Project

General

Profile

Actions

Bug #15941

closed

Issue with String#scrub when given block and receiver is modified in block

Added by luke-gru (Luke Gruber) almost 5 years ago. Updated over 4 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:93252]

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

scrub-modify-check.patch (3.82 KB) scrub-modify-check.patch jeremyevans0 (Jeremy Evans), 06/19/2019 05:47 PM

Updated by luke-gru (Luke Gruber) almost 5 years ago

I guess the solution here would be something similar to String#gsub, with str_mod_check.

Updated by jeremyevans0 (Jeremy Evans) almost 5 years ago

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) almost 5 years ago

Patch lgtm, thanks!

Actions #4

Updated by jeremyevans (Jeremy Evans) over 4 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

Also available in: Atom PDF

Like0
Like0Like0Like0Like0