From: merch-redmine@... Date: 2019-08-15T01:41:41+00:00 Subject: [ruby-core:94361] [Ruby master Bug#6436] Byte counting incorrect in BufferedIO (net/protocol.rb) Issue #6436 has been updated by jeremyevans0 (Jeremy Evans). Status changed from Assigned to Closed It looks like this issue was fixed between Ruby 2.4 and 2.5: ``` $ ruby24 -rnet/http -e "p Net::HTTP.start('www.falcom.co.jp', 443, :use_ssl=>true){|http| http.request_get('/'){|res| res.read_body{|c| p c.bytesize; c.force_encoding 'UTF-8'}}}" 0 16384 16384 16384 4604 2 5 0 16384 16384 16384 4604 2 5 -e: end of file reached (EOFError) $ ruby24 -rnet/http -e "p Net::HTTP.start('www.falcom.co.jp', 443, :use_ssl=>true){|http| http.request_get('/'){|res| res.read_body{|c| p c.bytesize}}}" 0 16384 16384 16384 4604 # $ ruby25 -rnet/http -e "p Net::HTTP.start('www.falcom.co.jp', 443, :use_ssl=>true){|http| http.request_get('/'){|res| res.read_body{|c| p c.bytesize; c.force_encoding 'UTF-8'}}}" 0 16384 16384 16384 4604 # ``` ---------------------------------------- Bug #6436: Byte counting incorrect in BufferedIO (net/protocol.rb) https://bugs.ruby-lang.org/issues/6436#change-80771 * Author: jcast (Jeremie Castagna) * Status: Closed * Priority: Normal * Assignee: nobu (Nobuyoshi Nakada) * Target version: * ruby -v: 1.9 * Backport: ---------------------------------------- BufferedIO's @rbuf counts bytes with String#size, but should use String#bytesize. This creates potential incorrect reading of a HTTP body when changing the encoding of each chuck passed by HTTP#read_body: http.read_body do |chunk| chunk.force_encoding "UTF-8" end ---Files-------------------------------- protocol.patch (4.39 KB) protocol.patch (2.63 KB) -- https://bugs.ruby-lang.org/ Unsubscribe: