From: "rhenium (Kazuki Yamaguchi) via ruby-core" Date: 2026-10-13T18:07:48+00:00 Subject: [ruby-core:127093] [Ruby Bug#22433] IO#sysread and IO#pread are inconsistent for length 0 and negative numbers 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/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/