diff options
| -rw-r--r-- | ext/stringio/stringio.c | 3 | ||||
| -rw-r--r-- | test/stringio/test_stringio.rb | 3 |
2 files changed, 6 insertions, 0 deletions
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index e9ca42e325..41aa71f893 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -167,6 +167,9 @@ strio_readbuf(struct StringIO *ptr, VALUE str) if (!NIL_P(str)) { StringValue(str); rb_str_modify(str); + if (str == ptr->string) { + rb_raise(rb_eArgError, "cannot read into the underlying string"); + } } return str; } diff --git a/test/stringio/test_stringio.rb b/test/stringio/test_stringio.rb index aca250a85a..0f61245a8a 100644 --- a/test/stringio/test_stringio.rb +++ b/test/stringio/test_stringio.rb @@ -765,6 +765,8 @@ class TestStringIO < Test::Unit::TestCase s = "" f.read(nil, s) assert_equal(Encoding::ASCII_8BIT, s.encoding, bug20418) + + assert_raise(ArgumentError) {f.read(1, f.string)} end def test_readpartial @@ -830,6 +832,7 @@ class TestStringIO < Test::Unit::TestCase assert_raise(EOFError) { f.pread(1, 5) } assert_raise(ArgumentError) { f.pread(-1, 0) } + assert_raise(ArgumentError) { f.pread(0, 0, f.string) } assert_raise(Errno::EINVAL) { f.pread(3, -1) } assert_raise(Errno::EINVAL) { f.pread(0, -1) } assert_raise(IOError) { StringIO.new(nil, "w").pread(3, 0) } |
