Project

General

Profile

Bug #15941

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

Added by luke-gru (Luke Gruber) 4 months ago. Updated 4 months ago.

Status:
Closed
Priority:
Normal
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

Associated revisions

Revision 0f283054
Added by jeremyevans (Jeremy Evans) 4 months ago

Check that String#scrub block does not modify receiver

Similar to the check used for String#gsub. Can fix possible
segfault.

Fixes [Bug #15941]

History

Updated by luke-gru (Luke Gruber) 4 months ago

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

Updated by jeremyevans0 (Jeremy Evans) 4 months 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) 4 months ago

Patch lgtm, thanks!

#4

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

Also available in: Atom PDF