Skip to content

Check frozen state after argument conversions in StringIO#reopen - #237

Merged
kou merged 1 commit into
ruby:masterfrom
kou:check-frozen-after-conversions
Nov 17, 2026
Merged

kou merged 1 commit into
ruby:masterfrom
kou:check-frozen-after-conversions

Conversation

@kou

@kou kou commented Nov 16, 2026

Copy link
Copy Markdown
Member

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.

@kou
kou deployed to release November 16, 2026 10:01 — with GitHub Actions Active
@kou
kou deployed to release November 16, 2026 10:01 — with GitHub Actions Active
@kou
kou force-pushed the check-frozen-after-conversions branch from ee642e8 to 411273c Compare November 16, 2026 11:58
@kou
kou deployed to release November 16, 2026 11:58 — with GitHub Actions Active
@kou
kou deployed to release November 16, 2026 11:58 — with GitHub Actions Active

@headius headius left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
kou force-pushed the check-frozen-after-conversions branch from 411273c to b9cc8e5 Compare November 17, 2026 01:47
@kou
kou deployed to release November 17, 2026 01:47 — with GitHub Actions Active
@kou
kou deployed to release November 17, 2026 01:47 — with GitHub Actions Active
@kou
kou merged commit 8e085ad into ruby:master Nov 17, 2026
68 checks passed
@kou
kou deleted the check-frozen-after-conversions branch November 17, 2026 02:00
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

1 active deployment
release — b9cc8e52 Deployed Nov 17, 2026 by kou via RubyGems (jruby) #298
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants