Repository navigation
Check frozen state after argument conversions in StringIO#reopen - #237
Merged
Merged
Conversation
kou
force-pushed
the
check-frozen-after-conversions
branch
from
November 16, 2026 11:58
ee642e8 to
411273c
Compare
headius
approved these changes
Nov 16, 2026
headius
left a comment
Contributor
There was a problem hiding this comment.
Looks good on the Java side.
`reopen` checked whether the receiver is frozen only before converting the arguments. If a conversion (`to_str` of the string or the mode, or `to_strio`) froze the receiver, `reopen` modified the frozen receiver. Check it again after the conversions in `strio_init()` and `strio_copy()`. `strio_init()` also keeps the parsed mode in a local variable until the check, so that the flags of the frozen receiver aren't changed. `strio_init()` and `strio_copy()` are also used by `initialize` and `initialize_copy`. So calling them directly on a frozen `StringIO` now raises `FrozenError` instead of modifying it. `dup` and `clone` aren't affected because the copy isn't frozen yet when `initialize_copy` is called. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
kou
force-pushed
the
check-frozen-after-conversions
branch
from
November 17, 2026 01:47
411273c to
b9cc8e5
Compare
matzbot
pushed a commit
to ruby/ruby
that referenced
this pull request
Nov 17, 2026
`StringIO#reopen` (ruby/stringio#237) `reopen` checked whether the receiver is frozen only before converting the arguments. If a conversion (`to_str` of the string or the mode, or `to_strio`) froze the receiver, `reopen` modified the frozen receiver. Check it again after the conversions in `strio_init()` and `strio_copy()`. `strio_init()` also keeps the parsed mode in a local variable until the check, so that the flags of the frozen receiver aren't changed. `strio_init()` and `strio_copy()` are also used by `initialize` and `initialize_copy`. So calling them directly on a frozen `StringIO` now raises `FrozenError` instead of modifying it. `dup` and `clone` aren't affected because the copy isn't frozen yet when `initialize_copy` is called. ruby/stringio@8e085ad71b Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
This branch was successfully deployed
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.
reopenchecked whether the receiver is frozen only before converting the arguments. If a conversion (to_strof the string or the mode, orto_strio) froze the receiver,reopenmodified the frozen receiver.Check it again after the conversions in
strio_init()andstrio_copy().strio_init()also keeps the parsed mode in a local variable until the check, so that the flags of the frozen receiver aren't changed.strio_init()andstrio_copy()are also used byinitializeandinitialize_copy. So calling them directly on a frozenStringIOnow raisesFrozenErrorinstead of modifying it.dupandclonearen't affected because the copy isn't frozen yet wheninitialize_copyis called.