Bug #6436
Byte counting incorrect in BufferedIO (net/protocol.rb)
Description
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
History
Updated by jcast (Jeremie Castagna) over 7 years ago
- File protocol.patch protocol.patch added
Patch file.
Updated by nobu (Nobuyoshi Nakada) over 7 years ago
- File protocol.patch protocol.patch added
Emacs diff-mode.el provides a function, diff-context->unified.
Updated by mame (Yusuke Endoh) over 7 years ago
- Status changed from Open to Assigned
- Assignee set to nobu (Nobuyoshi Nakada)
Thanks Jeremie,
Could you add a test to test/net/http/test_buffered_io.rb ?
Nobu, can you review the patch?
--
Yusuke Endoh mame@tsg.ne.jp
Updated by jeremyevans0 (Jeremy Evans) 4 months ago
- 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 #<Net::HTTPOK 200 OK readbody=true> $ 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 #<Net::HTTPOK 200 OK readbody=true>