-
Notifications
You must be signed in to change notification settings - Fork 102
readpartial must not return more data than requested #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The relevant bit of the JVM exception trace from JRuby is shown below:
Because |
FWIW the new error that JRuby will raise in this case:
This error ends up getting swallowed by net/http plumbing, but the result is the same. |
See jruby#6246 and ruby/webrick#43 for a discussion of this change.
See jruby#6246 and ruby/webrick#43 for a discussion of this change.
The change in #45 does appear to fix this issue. |
The contract of
readpartial
is that it will return up to the amount requested and no more. However the implementation ofreadpartial
in WEBrick's HTTPRequest does not honor this contract:webrick/lib/webrick/httprequest.rb
Lines 276 to 284 in 6b6990e
The assumption described here may hold in CRuby, but in JRuby's implementation of
copy_stream
we may use an intermediate buffer to hold data on its way, and ifreadpartial
returns more data than requested we will overflow that buffer. I will be fixing JRuby to raise a more Ruby-friendly error, but it's still going to be an error if wereadpartial
N bytes and get N+1.https://github.com/jruby/jruby/blob/a612f900243926e45a3d3465bc8ae5d9e5258cce/core/src/main/java/org/jruby/RubyIO.java#L4433-L4454
This is the root cause of a failure in
test_big_bodies
from test_httpproxy.rb as described in jruby/jruby#6246. Thecopy_stream
call deep inside the proxy test fails due to this buffer overflow, which causes the request's piped content to be prematurely closed and the proxy test to error out while trying to write request data.webrick/test/webrick/test_httpproxy.rb
Line 189 in ec5372f
The text was updated successfully, but these errors were encountered: