Skip to content
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

#readpartial is not respecting max length argument #384

Closed
akelmanson opened this issue Dec 22, 2016 · 7 comments
Closed

#readpartial is not respecting max length argument #384

akelmanson opened this issue Dec 22, 2016 · 7 comments
Assignees
Labels

Comments

@akelmanson
Copy link

Hi there,

According to IO#readpartial documentation, this method "reads at most maxlen bytes from the I/O stream", but HTTP::Response::Body#readpartial is returning more bytes than expected.

HTTP.get('http://www.rubydoc.info/github/httprb/http').body.readpartial(10).length

oj calls this method within C code and this misbehavior leads to Segmentation fault.

Thank you!

@ixti
Copy link
Member

ixti commented Dec 22, 2016

Can you please provide a simple example that will reproduce the issue? Because Body delegates #readpartial to IO at the end in fact with given maxlen.

Edit: Oh, I'm sorry misread your issue in a first place. you have example that shows that exactly...

@ixti ixti added the Bug label Dec 22, 2016
@ixti
Copy link
Member

ixti commented Dec 22, 2016

I confirm issue exists:

response = HTTP.get('http://www.rubydoc.info/github/httprb/http')
5.times { puts response.body.readpartial(10).length }
# 5401
# 10
# 10
# 10
# 10

@ixti
Copy link
Member

ixti commented Dec 22, 2016

The issue is because we read response headers first. And once they are fully fetched some of body might happen to be written in the chunk waiting for the first readpartial call.

@tarcieri
Copy link
Member

tarcieri commented Feb 9, 2017

@bidiu please ask on the Google Group:

https://groups.google.com/forum/#!forum/httprb

@tarcieri
Copy link
Member

tarcieri commented Feb 9, 2017

@bidiu no worries, just FYI that's the proper place to ask

@bidiu
Copy link

bidiu commented Feb 9, 2017

@tarcieri Thanks!

@bidiu
Copy link

bidiu commented Feb 9, 2017

@tarcieri No need to ask now, just checked the source of Body#each, figured it out: D

@ixti ixti self-assigned this Feb 10, 2017
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Jun 7, 2020
Update ruby-http to 4.4.1.


## 4.4.1 (2020-03-29)

* Backport [#590](httprb/http#590)
  Fix parser failing on some edge cases.
  ([@ixti])

## 4.4.0 (2020-03-25)

* Backport [#587](httprb/http#587)
  Fix redirections when server responds with multiple Location headers.
  ([@ixti])

* Backport [#599](httprb/http#599)
  Allow passing HTTP::FormData::{Multipart,UrlEncoded} object directly.
  ([@ixti])

## 4.3.0 (2020-01-09)

* Backport [#581](httprb/http#581)
  Add Ruby-2.7 compatibility.
  ([@ixti], [@janko])


## 4.2.0 (2019-10-22)

* Backport [#489](httprb/http#489)
  Fix HTTP parser.
  ([@ixti], [@fxposter])


## 4.1.1 (2019-03-12)

* Add `HTTP::Headers::ACCEPT_ENCODING` constant.
  ([@ixti])


## 4.1.0 (2019-03-11)

* [#533](httprb/http#533)
  Add URI normalizer feature that allows to swap default URI normalizer.
  ([@mamoonraja])


## 4.0.5 (2019-02-15)

* Backport [#532](httprb/http#532) from master.
  Fix pipes support in request bodies.
  ([@ixti])


## 4.0.4 (2019-02-12)

* Backport [#506](httprb/http#506) from master.
  Skip auto-deflate when there is no body.
  ([@Bonias])


## 4.0.3 (2019-01-18)

* Fix missing URL in response wrapped by auto inflate.
  ([@ixti])

* Provide `HTTP::Request#inspect` method for debugging purposes.
  ([@ixti])


## 4.0.2 (2019-01-15)

* [#506](httprb/http#506)
  Fix instrumentation feature.
  ([@paul])


## 4.0.1 (2019-01-14)

* [#515](httprb/http#515)
  Fix `#build_request` and `#request` to respect default options.
  ([@RickCSong])


## 4.0.0 (2018-10-15)

* [#482](httprb/http#482)
  [#499](httprb/http#499)
  Introduce new features injection API with 2 new feaures: instrumentation
  (compatible with ActiveSupport::Notification) and logging.
  ([@paul])

* [#473](httprb/http#473)
  Handle early responses.
  ([@janko-m])

* [#468](httprb/http#468)
  Rewind `HTTP::Request::Body#source` once `#each` is complete.
  ([@ixti])

* [#467](httprb/http#467)
  Drop Ruby 2.2 support.
  ([@ixti])

* [#436](httprb/http#436)
  Raise ConnectionError when writing to socket fails.
  ([@janko-m])

* [#438](httprb/http#438)
  Expose `HTTP::Request::Body#source`.
  ([@janko-m])

* [#446](httprb/http#446)
  Simplify setting a timeout.
  ([@mikegee])

* [#451](httprb/http#451)
  Reduce memory usage when reading response body.
  ([@janko-m])

* [#458](httprb/http#458)
  Extract HTTP::Client#build_request method.
  ([@tycoon])

* [#462](httprb/http#462)
  Fix HTTP::Request#headline to allow two leading slashes in path.
  ([@scarfacedeb])

* [#454](httprb/http#454)
  [#464](httprb/http#464)
  [#384](httprb/http#384)
  Fix #readpartial not respecting max length argument.
  ([@janko-m], [@marshall-lee])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants