Skip to content

#readpartial is not respecting max length argument #384

Description

@akelmanson

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!

Activity

  1. ixti commented on Dec 22, 2016

    @ixti
    Member

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

  2. ixti commented on Dec 22, 2016

    @ixti
    Member

    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
  3. ixti commented on Dec 22, 2016

    @ixti
    Member

    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.

  4. tarcieri commented on Feb 9, 2017

    @tarcieri
    Member
  5. tarcieri commented on Feb 9, 2017

    @tarcieri
    Member

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

  6. bidiu commented on Feb 9, 2017

    @bidiu

    @tarcieri Thanks!

  7. bidiu commented on Feb 9, 2017

    @bidiu

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

  8. self-assigned this
    on Feb 10, 2017
  9. added a commit that references this issue on Jun 7, 2020
  10. added theissue type on Mar 17, 2026
  11. added a commit that references this issue on May 11, 2026
  12. added a commit that references this issue on May 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions