Project

General

Profile

Actions

Bug #19380

closed

IO.read doesn't validate the offset argument

Added by andrykonchin (Andrew Konchin) about 1 year ago. Updated 12 months ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:112051]

Description

I've noticed that when passed negative offset argument IO.read raises a bit confusing error:

IO.read("read-test.txt", 1, -1)
# (irb):55:in `read': Invalid argument @ rb_io_seek - read-test.txt (Errno::EINVAL)

But error for invalid length argument is much more helpful:

IO.read("read-test.txt", -1)
# (irb):56:in `read': negative length -1 given (ArgumentError)

I would expect a similar ArgumentError exception to be raised for invalid offset argument instead of Invalid argument @ rb_io_seek - read-test.txt (Errno::EINVAL)

Updated by jeremyevans0 (Jeremy Evans) about 1 year ago

I've submitted a pull request to fix this: https://github.com/ruby/ruby/pull/7289

Actions #2

Updated by jeremyevans (Jeremy Evans) 12 months ago

  • Status changed from Open to Closed

Applied in changeset git|6c60006de5cfd75f10a1b4a3d822e2de41d22db6.


Raise ArgumentError if IO.read is provided negative offset

Fixes [Bug #19380]

Actions

Also available in: Atom PDF

Like0
Like0Like0