Project

General

Profile

Actions

Bug #18880

closed

IO#sysread on Windows does not validate arguments

Added by javanthropus (Jeremy Bopp) over 2 years ago. Updated about 2 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x64-mingw-ucrt]
[ruby-core:109054]

Description

When passing an invalid number of bytes to read, such as -1 , to IO#sysread on Linux, an ArgumentError is raised. On Windows Errno::EINVAL is raised instead.

r, w = IO.pipe
r.sysread(-1)

This raises ArgumentError on non-Windows and Errno::EINVAL on Windows.

Updated by javanthropus (Jeremy Bopp) about 2 years ago

I'm interested in submitting a patch for this, but which behavior is considered correct?

Updated by nobu (Nobuyoshi Nakada) about 2 years ago

The ArgumentError is correct.
Even on Windows, sysread(-2) raises an ArgumentError too.

At rounding up len in io.c:io_setstrbuf(), negative values are not considered.

Updated by javanthropus (Jeremy Bopp) about 2 years ago

I submitted PR https://github.com/ruby/ruby/pull/6354 with a simple fix. I don't have a Windows system to test with though, so I couldn't verify that it works.

Actions #4

Updated by javanthropus (Jeremy Bopp) about 2 years ago

  • Status changed from Open to Closed

Applied in changeset git|684353fc03afd6e7c887b65bd18f0b3aeb98101c.


[Win32] Negative length IO#sysread

Raise ArgumentError in IO#sysread on Windows when given a negative
length.

Fixes [Bug #18880]

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0