From: "nagachika (Tomoyuki Chikanaga)" Date: 2021-09-18T07:51:32+00:00 Subject: [ruby-core:105338] [Ruby master Bug#17661] IO#each will segfault when if file is closed inside an `each_byte` block Issue #17661 has been updated by nagachika (Tomoyuki Chikanaga). Backport changed from 2.6: UNKNOWN, 2.7: REQUIRED, 3.0: REQUIRED to 2.6: UNKNOWN, 2.7: REQUIRED, 3.0: DONE ruby_3_0 e6e25b794d8db52e1df85a02f28846ad7eb82d49 merged revision(s) 13939d61b4b69bd109c5f41303c79868d639fa44. ---------------------------------------- Bug #17661: IO#each will segfault when if file is closed inside an `each_byte` block https://bugs.ruby-lang.org/issues/17661#change-93752 * Author: tenderlovemaking (Aaron Patterson) * Status: Closed * Priority: Normal * Backport: 2.6: UNKNOWN, 2.7: REQUIRED, 3.0: DONE ---------------------------------------- As reported here: https://twitter.com/asterite/status/1363487990203506689 when iterating through a file's contents with #each_byte, if the filehandle is closed inside of the block yielded to by #each byte, this condition is not detected, and a segmentation fault is thrown. Repro: ```ruby file = http://File.open(__FILE__) file.each_byte do |byte| p byte file.close end ``` Proposed fix is here: https://github.com/ruby/ruby/pull/4217 -- https://bugs.ruby-lang.org/ Unsubscribe: