Project

General

Profile

Bug #6436

Byte counting incorrect in BufferedIO (net/protocol.rb)

Added by jcast (Jeremie Castagna) over 7 years ago. Updated 4 days ago.

Status:
Closed
Priority:
Normal
Target version:
-
ruby -v:
1.9
Backport:
[ruby-core:45062]

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

protocol.patch (4.39 KB) protocol.patch jcast (Jeremie Castagna), 05/16/2012 05:27 AM
protocol.patch (2.63 KB) protocol.patch nobu (Nobuyoshi Nakada), 05/16/2012 10:05 AM

History

Updated by nobu (Nobuyoshi Nakada) over 7 years ago

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 days 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>

Also available in: Atom PDF