[ruby-core:127092] [Ruby Bug#22433] IO#sysread and IO#pread are inconsistent for length 0 and negative numbers
Issue #22433 has been reported by rhenium (Kazuki Yamaguchi). ---------------------------------------- Bug #22433: IO#sysread and IO#pread are inconsistent for length 0 and negative numbers https://bugs.ruby-lang.org/issues/22433 * Author: rhenium (Kazuki Yamaguchi) * Status: Open * Backport: 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN ---------------------------------------- When the length is 0 and an output buffer is given, the buffer is not cleared correctly. [Bug #18421] fixed the same bug for `IO#readpartial` and `IO#read_nonblock`, but it omitted `IO#sysread` and `IO#pread`: ```ruby File.open("/dev/null"){|f|f.read(0,"abc")} #=> "" # Returns the buffer unmodified File.open("/dev/null"){|f|f.sysread(0,"abc")} #=> "abc" File.open("/dev/null"){|f|f.pread(0,0,"abc")} #=> "abc" ``` These methods should also reject negative lengths: ```ruby File.open("/dev/null"){|f|f.read(-1,"abc")} # ArgumentError "negative length -1 given" # Tries to read (size_t)-1 bytes File.open("/dev/null"){|f|f.sysread(-1,"abc")} # Errno::EFAULT File.open("/dev/null"){|f|f.pread(-1,0,"abc")} # Errno::EFAULT ``` -- https://bugs.ruby-lang.org/
Issue #22433 has been updated by rhenium (Kazuki Yamaguchi). I've opened a GitHub PR: https://github.com/ruby/ruby/pull/19323 ---------------------------------------- Bug #22433: IO#sysread and IO#pread are inconsistent for length 0 and negative numbers https://bugs.ruby-lang.org/issues/22433#change-119488 * Author: rhenium (Kazuki Yamaguchi) * Status: Open * Backport: 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN ---------------------------------------- When the length is 0 and an output buffer is given, the buffer is not cleared correctly. [Bug #18421] fixed the same bug for `IO#readpartial` and `IO#read_nonblock`, but it omitted `IO#sysread` and `IO#pread`: ```ruby File.open("/dev/null"){|f|f.read(0,"abc")} #=> "" # Returns the buffer unmodified File.open("/dev/null"){|f|f.sysread(0,"abc")} #=> "abc" File.open("/dev/null"){|f|f.pread(0,0,"abc")} #=> "abc" ``` These methods should also reject negative lengths: ```ruby File.open("/dev/null"){|f|f.read(-1,"abc")} # ArgumentError "negative length -1 given" # Tries to read (size_t)-1 bytes File.open("/dev/null"){|f|f.sysread(-1,"abc")} # Errno::EFAULT File.open("/dev/null"){|f|f.pread(-1,0,"abc")} # Errno::EFAULT ``` -- https://bugs.ruby-lang.org/
participants (1)
-
rhenium (Kazuki Yamaguchi)