116 Commits
Author SHA1 Message Date
Hiroshi SHIBATAandClaude Opus 5.5 e1488e6b75 [ruby/stringio] Convert whence to Integer again in StringIO#seek
d3c5e6d compared whence with Fixnums directly, so a Float or an object with `to_int`, which IO#seek and the JRuby version accept, raised Errno::EINVAL.

https://github.com/ruby/stringio/commit/6ecc66a590

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-10 23:54:42 +00:00
KBS 0f0d3172be [ruby/stringio] Fix the zero-fill bounds in ungetbyteCommon on JRuby
(https://github.com/ruby/stringio/pull/225)

`Arrays.fill(byte[], int, int, byte)` takes **fromIndex, toIndex**, but
`ungetbyteCommon` passes `memset`'s **destination, length**:

```java
if (rest > cl) Arrays.fill(strBytes, len, rest - cl, (byte) 0);
```

straight from `ext/stringio/stringio.c:1181`, `memset(s + len, 0, rest -
cl)`. It also drops the ByteList `begin` offset that the C `s +`
supplies.

Pushing back onto a StringIO positioned more than the pushback length
past the end of its string then throws instead of zero-filling:

```ruby
s = StringIO.new("abc"); s.pos = 5; s.ungetbyte("d")
# JRuby:  Java::JavaLang::IllegalArgumentException: fromIndex(3) > toIndex(1)
# CRuby:  s.string == "abc\0d", s.pos == 4
```

The two siblings in this file already spell the correct form —
`truncate` (`StringIO.java:1462`) uses `buf.getBegin() + plen,
buf.getBegin() + l`, and `strioExtend` (`:1044-1048`) uses `begin +
olen, begin + pos`. This one line is the odd one out, so the fix reuses
their shape rather than adding anything.

The added expectations extend the existing `test_ungetc_padding` /
`test_ungetbyte_padding`, which stop one short: both start from
`StringIO.new()`, so `len == 0` makes the wrong call accidentally
correct.

<details>
<summary>Verification</summary>

Both backends built from this clone, `$LOADED_FEATURES` printed and
checked on every row.

A differential sweep of 2100 cases (7 base strings x 25 positions x 6
pushback values x `ungetbyte`/`ungetc`), JRuby against the C extension:

| build | rows differing from CRuby |
|---|---|
| current `master` | **132** |
| with the fix | **0** |

Every one of the 132 is the `IllegalArgumentException`.

| row | result |
|---|---|
| the two padding tests on `master` | 2 errors |
| with the fix | 2 tests, 12 assertions, 0 failures, 0 errors |
| revert | 2 errors |
| widen the guard to `rest > 0` | 1 error |
| `fromIndex` one low | 1 failure, 1 error |
| `toIndex` one high | passes — see below |

That last mutant survives, and I checked whether it was a gap in my test
or genuinely equivalent: the extra byte lands at `s + pos` after `pos -=
cl`, which `System.arraycopy(..., strBytes, s + pos, cl)` two lines
later overwrites unconditionally. Sweeping it over the same 2100 cases
gives **0 differences from the fixed build**, so it is an equivalent
mutant rather than an uncovered line, and I did not add a row for it.

Full `test/stringio/test_stringio.rb`: CRuby 3.2 **104 tests, 646
assertions, 0 failures, 0 errors**; JRuby 10.0.6 **104 tests, 643
assertions, 0 failures, 0 errors**.

Every added expectation was run against the C extension first, so it
encodes CRuby behaviour rather than my reading of it.

Two things I want on the record. The `s +` half is not separately
covered — I could not construct a StringIO whose backing ByteList has
`begin != 0` through the public API. It is included because both
siblings and the C both require it; if you would rather keep the change
minimal, the two-index correction alone fixes the crash. And
`ruby/.github`'s SECURITY.md routes vulnerabilities privately: this is
the JVM's own bounds check firing rather than memory unsafety, and I
could not produce any stale-byte disclosure, so I filed publicly — say
the word if you would rather it had gone the other route.

The CI matrix runs `jruby-head`; the closest I could obtain is JRuby
10.0.6. Note `jruby:9.4` cannot compile `ext/java` at master at all
(`Helpers.memchr` signature mismatch), so 10.x is already the floor.
</details>

---

Disclosure: I used Claude (an AI assistant) while preparing this change.
Every result above I ran and verified myself.

https://github.com/ruby/stringio/commit/9d3e502b3a
2026-09-13 21:51:26 +00:00
Nobuyoshi NakadaandPranjali Thakur d5f27aea78 [ruby/stringio] Skip chompped record separator
Fix ruby/stringio#218.

https://github.com/ruby/stringio/commit/cff28a1dab

Co-Authored-By: Pranjali Thakur <pranjali@depthfirst.com>
2026-07-10 11:04:24 +00:00
Nobuyoshi Nakada 1d2d4ac734 [ruby/stringio] Cannot read into the underlying string
Fix https://hackerone.com/reports/3716987

https://github.com/ruby/stringio/commit/4ed1d6b7cf
2026-05-07 05:40:09 +00:00
Nobuyoshi Nakada 66b1559d39 [ruby/stringio] Check arguments in pread
https://github.com/ruby/stringio/commit/efe8351676
2026-05-07 05:03:57 +00:00
Charles Oliver Nutter 571ce8d779 [ruby/stringio] Add tests for read-only methods on frozen StringIO
See #120

https://github.com/ruby/stringio/commit/8cba5aac0a
2026-03-03 03:29:20 +00:00
Nobuyoshi Nakada 28f760bf70 [ruby/stringio] Suppress warnings against pattern matching on ruby 2.7
https://github.com/ruby/stringio/commit/cf58a203eb
2025-11-10 04:10:10 +00:00
kares 480080b5bf [ruby/stringio] fix: (jruby) failing to clean buffer's code-range
same bug as: https://github.com/jruby/jruby/issues/9035

https://github.com/ruby/stringio/commit/65b144b175
2025-11-04 18:54:15 +00:00
Sutou Kouhei f2c7968a42 [ruby/stringio] Fix test name
(https://github.com/ruby/stringio/pull/139)

https://github.com/ruby/stringio/commit/0edc8e22da
2025-08-12 01:16:46 +00:00
Nobuyoshi Nakada b4d5ebcd12 [ruby/stringio] Fix SEGV at eof? on null StringIO
https://github.com/ruby/stringio/commit/29b9133332
2025-08-09 11:12:48 +00:00
Nobuyoshi Nakada 31f2d8990d [ruby/stringio] Fix SEGV at read/pread on null StringIO
https://github.com/ruby/stringio/commit/113dd5a55e
2025-08-09 11:12:48 +00:00
koh-sh 23c0113932 [ruby/stringio] fix: prevent segfault in StringIO#seek with SEEK_END
on null device
(https://github.com/ruby/stringio/pull/137)

Fixes segmentation fault when calling `seek` with `SEEK_END` on null
device StringIO created by
  `StringIO.new(nil)`.

```bash
ruby -e "require 'stringio'; StringIO.new(nil).seek(0, IO::SEEK_END)"
```

I tested with below versions.

```bash
[koh@Kohs-MacBook-Pro] ~
% ruby -v;gem info stringio;sw_vers
ruby 3.4.5 (2025-07-16 revision https://github.com/ruby/stringio/commit/20cda200d3) +PRISM [arm64-darwin24]

*** LOCAL GEMS ***

stringio (3.1.2)
    Authors: Nobu Nakada, Charles Oliver Nutter
    Homepage: https://github.com/ruby/stringio
    Licenses: Ruby, BSD-2-Clause
    Installed at (default): /Users/koh/.local/share/mise/installs/ruby/3.4.5/lib/ruby/gems/3.4.0

    Pseudo IO on String
ProductName:            macOS
ProductVersion:         15.5
BuildVersion:           24F74
[koh@Kohs-MacBook-Pro] ~
%
```

https://github.com/ruby/stringio/commit/9399747bf9
2025-08-09 09:30:27 +00:00
Jeremy Evans 18d395e078 [ruby/stringio] Do not issue warning when calling set_encoding if string is chilled
StringIO does not warn for unchilled unfrozen string or for frozen
string, so it should not warn for chilled string.

https://github.com/ruby/stringio/commit/4ac33b8c70
2025-05-13 03:20:09 +00:00
Nobuyoshi Nakada 7ef9110b1e [ruby/stringio] Fix SEGV at unget to a null device StringIO
https://github.com/ruby/stringio/commit/eb4ee49218
2025-02-21 12:06:19 +00:00
Nobuyoshi Nakada fa6b9f75ef [ruby/stringio] Suppress a warning for the chilled string
https://github.com/ruby/stringio/commit/4a35291ed3
2025-02-21 12:06:19 +00:00
Charles Oliver Nutter 7d7984642c [ruby/stringio] Allow seek when underlying string is frozen
(https://github.com/ruby/stringio/pull/121)

Fixes https://github.com/ruby/stringio/pull/119. Adds a test for this expectation.

https://github.com/ruby/stringio/commit/3f90fe44c6
2025-02-21 00:37:40 +00:00
a27758ad4e [ruby/stringio] Make sure shared buffer is copied on mutation
(https://github.com/ruby/stringio/pull/117)

We need to ensure shared buffers are made independent on mutation.
Otherwise we could end up mutating unrelated string buffers.

---------

https://github.com/ruby/stringio/commit/5101cfb030

Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
Co-authored-by: Alan Wu <XrXr@users.noreply.github.com>
Co-authored-by: Aaron Patterson <aaron.patterson@gmail.com>
Co-authored-by: Sutou Kouhei <kou@cozmixng.org>
2025-02-20 00:18:08 +00:00
Nobuyoshi Nakada 348a534153 [ruby/stringio] Copy from the relocated string
When ungetting the string same as the same buffer string, extending
the buffer can move the pointer in the argument.  Reported by manun
Manu (manun) at https://hackerone.com/reports/2805165.

https://github.com/ruby/stringio/commit/95c1194832
2024-11-05 05:01:03 +00:00
Jean Boussier 15501e13d7 [ruby/stringio] Remove special handling of chilled strings
[Feature #20205]

Followup: https://github.com/ruby/stringio/pull/94

They no longer need to be special cases. If StringIO end up
mutating a chilled string, a warning will be emitted.

https://github.com/ruby/stringio/commit/dc62d65449
2024-05-30 15:11:48 +00:00
Jean byroot BoussierandJean Boussier 75154dec73 [ruby/stringio] strio_read: preserve buffer encoding on partial
reads
(https://github.com/ruby/stringio/pull/95)

[[Bug #20418]](https://bugs.ruby-lang.org/issues/20418)

Ruby IO#read preserves the encoding on partial read, but change it when
reading the whole IO

from commit https://github.com/ruby/ruby/commit/0ca7036682da:
> * io.c (read_all): should associate default external encoding.
> * io.c (io_read): should NOT associate default external encoding.

https://github.com/ruby/stringio/commit/073172da31

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2024-04-17 01:29:18 +00:00
Étienne BarriéandJean Boussier 0f5ab4ad52 [ruby/stringio] Eagerly defrost chilled strings
[Feature #20390]

https://github.com/ruby/stringio/commit/17ee957f34

Co-authored-by: Jean Boussier <byroot@ruby-lang.org>
2024-03-28 02:27:19 +09:00
Nobuyoshi Nakada a1ced60692 [ruby/stringio] NULL StringIO by StringIO.new(nil)
https://github.com/ruby/stringio/commit/779f71359d
2024-03-15 04:34:14 +00:00
Nobuyoshi Nakada 3f8ef7ff7c [ruby/stringio] Define StringIO::MAX_LENGTH
https://github.com/ruby/stringio/commit/0205bd1c86
2024-03-13 13:20:23 +00:00
Charles Oliver Nutter 0b7487b44e [ruby/stringio] Various cleanup for JRuby ext
(https://github.com/ruby/stringio/pull/85)

* Fix compile warnings on latest Java.
* Adjust one test for JRuby erroring on bad pos= value.
* Replace hard JVM synchronization with a spin lock.
* Avoid duplicate reads of state fields where possible.
* Remove long-deprecated codepoints, chars, bytes, lines methods.
* Mark fcntl as not implemented
* Split most of the remaining variable-arity methods.

https://github.com/ruby/stringio/commit/31a9d42e6c
2024-03-13 04:46:54 +00:00
tomoya ishida fd1bafc11f [ruby/stringio] Fix ascii_only? flag in strio_write
(https://github.com/ruby/stringio/pull/77)

Followup of #79

`rb_str_resize()` was changed by https://github.com/ruby/ruby/commit/b0b9f7201acab05c2a3ad92c3043a1f01df3e17f  .

```c
rb_str_resize(string, shorter) // clear ENC_CODERANGE in some case
rb_str_resize(string, longer) // does not clear ENC_CODERANGE anymore
```

```c
// rb_str_resize in string.c
if (slen > len && ENC_CODERANGE(str) != ENC_CODERANGE_7BIT) {
  ENC_CODERANGE_CLEAR(str);
}
```

I think this change is based on an assumption that appending null bytes
will not change flag `ascii_only?`.

`strio_extend()` will make the string longer if needed, and update the
flags correctly for appending null bytes.
Before `memmove()`, we need to `rb_str_modify()` because updated flags are not
updated for `memmove()`.

https://github.com/ruby/stringio/commit/b31a538576
2024-01-18 03:42:21 +00:00
Nobuyoshi Nakada 6283ae8d36 [ruby/stringio] Update the coderange after overwrite
Fix https://bugs.ruby-lang.org/issues/20185

https://github.com/ruby/stringio/commit/8230552a46
2024-01-16 15:06:22 +00:00
Sutou Kouhei 7ed37388fb [ruby/stringio] Add missing row separator encoding conversion
(https://github.com/ruby/stringio/pull/69)

The conversion logic is borrowed from ruby/ruby's io.c:
https://github.com/ruby/ruby/blob/40391faeab608665da87a05c686c074f91a5a206/io.c#L4059-L4079

Fix ruby/stringio#68

Reported by IWAMOTO Kouichi. Thanks!!!

https://github.com/ruby/stringio/commit/4b170c1a68
2023-11-08 00:46:17 +00:00
Jean byroot BoussierandJean Boussier f087f2c74c [ruby/stringio] StringIO#pread: handle 0 length like IO#pread
(https://github.com/ruby/stringio/pull/67)

Fix: https://github.com/ruby/stringio/issues/66

If length is 0, IO#pread don't even try to read the IO, it simply return
the buffer untouched if there is one or a new empty buffer otherwise.

It also doesn't validate the offset when length is 0.

cc @jdelStrother @kou

https://github.com/ruby/stringio/commit/37e9279337

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2023-10-05 07:44:08 +00:00
Sutou Kouhei 0a219ef44a jruby: Add StringIO::VERSION (#59)
Fixes GH-57
2023-08-29 18:15:05 +09:00
Jean byroot BoussierandJean Boussier fd8dd71996 Implement StringIO#pread (#56)
Both for being closer to real IOs and also because it's a convenient API
in multithreaded scenarios.

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2023-08-02 18:18:17 +09:00
Nobuyoshi Nakada 21dced8b01 [ruby/stringio] [Bug #19389] Fix chomping with longer separator
https://github.com/ruby/stringio/commit/eb322a9716
2023-01-28 13:00:08 +00:00
Nobuyoshi Nakada 302f353fd9 [ruby/stringio] Fix the result of StringIO#truncate so compatible with File
https://github.com/ruby/stringio/commit/16847fea32
2022-07-01 00:52:29 +09:00
Nobuyoshi Nakada d3e986d9ab [ruby/stringio] Accept external and internal encodings pair
Fix https://github.com/ruby/stringio/pull/16

https://github.com/ruby/stringio/commit/c8a69e80d2
2022-05-30 14:48:44 +09:00
Jeremy Evans 609d73e892 [ruby/stringio] Fix handling of chomp with paragraph separator
Try to mirror IO behavior, where chomp takes out the entire paragraph
separators between entries, but does not chomp a single line separator
at the end of the string.

Partially Fixes [Bug #18768]

https://github.com/ruby/stringio/commit/a83ddbb7f0
2022-05-30 13:10:46 +09:00
Jeremy Evans adaaf12857 [ruby/stringio] Ignore chomp keyword for nil separator
nil separator means no separator at all, so nothing should be
chomped.

Partial fix for Ruby [Bug #18770]

https://github.com/ruby/stringio/commit/feaa2ec631
2022-05-30 13:01:17 +09:00
Jeremy Evans 1f82269f4e [ruby/stringio] Fix each with multiple character string and chomp
Previously, this could result in an infinite loop.  Always update
the e pointer in this case, setting w when chomping so the chomped
data is not included in the output.

Fixes [Bug #18769]

https://github.com/ruby/stringio/commit/4bf64d5130
2022-05-30 12:55:47 +09:00
Nobuyoshi Nakada bb6357cddd [ruby/stringio] Fix expanding size at ungetc/ungetbyte
https://github.com/ruby/stringio/commit/a35268a3ac
2022-05-30 12:51:37 +09:00
Nobuyoshi Nakada 32a13591e0 [ruby/stringio] Check if closed in loop
[Bug #17675] https://bugs.ruby-lang.org/issues/17675

https://github.com/ruby/stringio/commit/1ed61d0cbc
2021-03-08 10:13:29 +09:00
Hiroshi SHIBATA c3c1800708 Prefer to use omit 2021-03-08 09:34:16 +09:00
Yoann Lecuyer b3c1c767ea [stringio] fix stringio codepoint enumerator off by one error 2020-08-27 23:41:22 +09:00
Nobuyoshi Nakada ddb2acbba6 [ruby/stringio] No compatibility check in US-ASCII case
https://github.com/ruby/stringio/commit/59df1c8293
2020-07-20 14:59:19 +09:00
Nobuyoshi Nakada c62aff1632 [ruby/stringio] Added non-ASCII but convertible encoding case
https://github.com/ruby/stringio/commit/1d28e5c969
2020-07-20 14:59:19 +09:00
Nobuyoshi Nakada 6ff9604f85 [ruby/stringio] Raise an error if encoding conversion not succeeded
As `rb_str_conv_enc()` returns the argument string object itself
unchanged when any conversion failed, check the incompatibility in
that case.

Fixes https://github.com/ruby/stringio/issues/13

https://github.com/ruby/stringio/commit/ede6bdcc71
2020-07-20 14:59:19 +09:00
Jean Boussier e257c08f2e [ruby/stringio] StringIO#initialize default to the source string encoding
[Bug #16497]

https://github.com/ruby/stringio/commit/4958a5ccab
2020-03-15 18:43:01 +09:00
Jeremy Evans ebc884461b [ruby/stringio] Remove taint support
Ruby 2.7 deprecates taint and it no longer has an effect.
The lack of taint support should not cause a problem in
previous Ruby versions.

https://github.com/ruby/stringio/commit/60ee9ccd95
2019-10-31 16:24:02 +09:00
卜部昌平 11b6ff12af more use of RbConfig::LIMITS
`8 * RbConfig::SIZEOF` ... is not straight.
2019-10-08 11:21:20 +09:00
Nobuyoshi Nakada cad41bb6d3 [ruby/stringio] Supported BOM
https://github.com/ruby/stringio/commit/b249631c43
2019-08-14 11:20:58 +09:00
Nobuyoshi Nakada c8f9e9a2a0 [ruby/stringio] stringio: encoding support
https://github.com/ruby/stringio/commit/7b20075ab0
2019-08-14 11:20:57 +09:00
Nobuyoshi Nakada e0c4cb2ea1 Define singleton method on each new objects 2019-06-28 15:22:27 +09:00
shyouhei d154bec0d5 setbyte / ungetbyte allow out-of-range integers
* string.c: String#setbyte to accept arbitrary integers [Bug #15460]

* io.c: ditto for IO#ungetbyte

* ext/strringio/stringio.c: ditto for StringIO#ungetbyte



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66824 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-15 06:41:58 +00:00