Bug #17675
closedStringIO#each_byte doesn't check for readabilty while iterating
Description
Bug #17661 is a failure to check readability on each_byte
of an IO, causing a segmentation fault.
StringIO has an independent, but related implementation, and it shares the same flaw in its implementation, where it fails to check for the readability of the StringIO object while iterating over the bytes. Unlike IO, this does not result in a segmentation fault. It does, however, allow the continued reading from an object that has been closed.
require "stringio"
strio = StringIO.new
strio.each_byte do |byte|
puts byte
strio.close
end
That code should print the first byte, and then throw an IOError, but instead, it iterates through the entire data buffer for the object, calling the block for each byte, without ever raising an exception.
I have a PR for this which I will submit on Github and link to.
The PR simply inserts an appropriate check into the loop for each_byte
.
Updated by wyhaines (Kirk Haines) almost 4 years ago
The PR is:
Updated by nobu (Nobuyoshi Nakada) almost 4 years ago
Please submit to https://github.com/ruby/stringio
Updated by nobu (Nobuyoshi Nakada) almost 4 years ago
- Status changed from Open to Closed
Applied in changeset git|32a13591e0bb6e96b05452e214f14eda21ee3aa9.
[ruby/stringio] Check if closed in loop
Updated by nagachika (Tomoyuki Chikanaga) about 3 years ago
- Backport changed from 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN to 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: DONE
Backported into ruby_3_0 at e6fced73e55dda487f026c929d97542cf1832252. Thank you hsbt san.