Actions
Bug #19380
closedIO.read doesn't validate the offset argument
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) almost 2 years ago
I've submitted a pull request to fix this: https://github.com/ruby/ruby/pull/7289
Updated by jeremyevans (Jeremy Evans) almost 2 years 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
Like0
Like0Like0