From f0063cb05a1d572a4e38433566bb9ec85b3425fe Mon Sep 17 00:00:00 2001 From: Charlie Crighton Date: Sat, 12 Aug 2023 21:10:40 +1200 Subject: [PATCH] Ensure that all form data is read to content-length --- phew/server.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/phew/server.py b/phew/server.py index 60a3113..2540e3b 100644 --- a/phew/server.py +++ b/phew/server.py @@ -245,7 +245,14 @@ async def _handle_request(reader, writer): if request.headers["content-type"].startswith("application/json"): request.data = await _parse_json_body(reader, request.headers) if request.headers["content-type"].startswith("application/x-www-form-urlencoded"): - form_data = await reader.read(int(request.headers["content-length"])) + form_data = b"" + content_length = int(request.headers["content-length"]) + while content_length > 0: + data = await reader.read(content_length) + if len(data) == 0: + break + content_length -= len(data) + form_data += data request.form = _parse_query_string(form_data.decode()) route = _match_route(request)