Project

General

Profile

Actions

Bug #6436

closed

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

Added by jcast (Jeremie Castagna) almost 12 years ago. Updated over 4 years ago.

Status:
Closed
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

Updated by nobu (Nobuyoshi Nakada) almost 12 years ago

Emacs diff-mode.el provides a function, diff-context->unified.

Updated by mame (Yusuke Endoh) almost 12 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

Updated by jeremyevans0 (Jeremy Evans) over 4 years 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>
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0