You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf(asgi): avoid quadratic request body aggregation and add explicit ASGI body cap #70
Current ASGI bridge request-body read path aggregates chunks using repeated bytes concatenation (body += chunk), which causes repeated realloc/copy under fragmented payloads. It also has no explicit ASGI-side cap before full aggregation.
This can create avoidable CPU/memory pressure and is a practical DoS vector for large or highly chunked bodies.
Current code
oxyroute/asgi.py in asgi_to_rsgi(...):
read loop appends chunks to body (bytes)
no ASGI-side max-body guard
Goals
Replace repeated bytes concatenation with an O(n) accumulation strategy.
Introduce explicit ASGI-side max-body limit (aligned with existing body-size policy).
Return a clear error/termination behavior on limit breach.
Proposed direction
Accumulate into bytearray or list[bytes] and join once.
Enforce max bytes while reading chunks.
Keep behavior consistent with framework-level 413 handling semantics where possible.
Acceptance criteria
No body += chunk pattern in ASGI bridge hot read path.
Payload limit is enforced during read (not only after full aggregation).
Add tests for:
normal chunked body path;
over-limit chunked body path.
Existing ASGI tests continue to pass.
Out of scope
Full streaming request-body API for handlers (separate issue).
Activity