Skip to content

Commit ca54a60

Browse files
baywetCopilot
andcommitted
fix(declarative): keep decoder bounds representable
Co-authored-by: Copilot <[email protected]> Copilot-Session: 9015c274-1215-4163-94db-643befd21f8d
1 parent 4beaa96 commit ca54a60

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

‎python/packages/declarative/agent_framework_declarative/_workflows/_http_handler.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from __future__ import annotations
2222

2323
import asyncio
24+
import sys
2425
import zlib
2526
from collections.abc import AsyncGenerator, Awaitable, Callable, Mapping
2627
from dataclasses import dataclass, field, replace
@@ -417,7 +418,7 @@ def decode(self, data: bytes) -> bytes:
417418
self._input.extend(data)
418419
return b""
419420
try:
420-
decoded = self._decoder.decompress(data, self._limit - self._decoded + 1)
421+
decoded = self._decoder.decompress(data, min(self._limit - self._decoded + 1, sys.maxsize))
421422
except zlib.error as exc:
422423
raise httpx.DecodingError(str(exc)) from exc
423424
self._decoded += len(decoded)

‎python/packages/declarative/tests/test_default_http_request_handler.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,20 @@ async def test_empty_method_raises(self) -> None:
768768

769769

770770
class TestResponseBodyLimits:
771+
@pytest.mark.parametrize("limit", [sys.maxsize, sys.maxsize + 1, 10**100])
772+
@pytest.mark.parametrize("encoding", ["gzip", "deflate"])
773+
async def test_large_response_body_limit_accepts_small_encoded_body(self, limit: int, encoding: str) -> None:
774+
body = gzip.compress(b"ok") if encoding == "gzip" else zlib.compress(b"ok")
775+
stream = _ResponseStream([body])
776+
response = httpx.Response(200, headers={"Content-Encoding": encoding}, stream=stream)
777+
async with (
778+
httpx.AsyncClient(transport=httpx.MockTransport(lambda request: response)) as client,
779+
DefaultHttpRequestHandler(client=client, max_response_body_bytes=limit) as handler,
780+
):
781+
result = await handler.send(HttpRequestInfo(method="GET", url="https://api.example.test/items"))
782+
assert result.body == "ok"
783+
assert stream.closed
784+
771785
@pytest.mark.parametrize("client_source", ["caller", "provider"])
772786
@pytest.mark.parametrize(
773787
("client_encoding", "request_encoding", "expected"),

0 commit comments

Comments
 (0)