Skip to content

HTTPResponse.stream can fall into infinite loop when amt is zero #3793

Description

@Cycloctane

Subject

HTTPResponse.stream generator can safely handle the situation when amt is positive integer, negative integer and None. However, amt=0 can lead to catastrophic infinite loop (while HTTPResponse.read(0) is legit). This behavior is implicit, not covered in docs and tests.

Steps to Reproduce

import urllib3

r = urllib3.request("GET", "https://example.com", preload_content=False)

for chunk in r.stream(0):
    print(chunk)

Actual Behavior

Run into infinite loop

Expected Behavior

Anything else (handled the same way as None / explicitly raise a ValueError / return with empty output, etc.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions