ruby-changes:73520
From: Jeremy <ko1@a...>
Date: Sun, 11 Sep 2022 23:08:33 +0900 (JST)
Subject: [ruby-changes:73520] 684353fc03 (master): [Win32] Negative length `IO#sysread`
https://git.ruby-lang.org/ruby.git/commit/?id=684353fc03 From 684353fc03afd6e7c887b65bd18f0b3aeb98101c Mon Sep 17 00:00:00 2001 From: Jeremy Bopp <jeremy@b...> Date: Sun, 11 Sep 2022 09:08:14 -0500 Subject: [Win32] Negative length `IO#sysread` Raise `ArgumentError` in `IO#sysread` on Windows when given a negative length. Fixes [Bug #18880] --- io.c | 3 ++- test/ruby/test_io.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/io.c b/io.c index 30165e1616..675c0ad3c2 100644 --- a/io.c +++ b/io.c @@ -3053,7 +3053,8 @@ static int https://github.com/ruby/ruby/blob/trunk/io.c#L3053 io_setstrbuf(VALUE *str, long len) { #ifdef _WIN32 - len = (len + 1) & ~1L; /* round up for wide char */ + if (len > 0) + len = (len + 1) & ~1L; /* round up for wide char */ #endif if (NIL_P(*str)) { *str = rb_str_new(0, len); diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index d6fcf16ddd..f791b4415d 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -2213,6 +2213,14 @@ class TestIO < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io.rb#L2213 end) end + def test_sysread_with_negative_length + make_tempfile {|t| + open(t.path) do |f| + assert_raise(ArgumentError) { f.sysread(-1) } + end + } + end + def test_flag make_tempfile {|t| assert_raise(ArgumentError) do -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/