Skip to content

Commit

Permalink
Merge pull request #3258 from pajod/patch-empty-chunksize
Browse files Browse the repository at this point in the history
gracefully handle chunked encoding missing size
  • Loading branch information
benoitc authored Aug 6, 2024
2 parents 79b9a52 + cabc666 commit 7f55988
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions gunicorn/http/body.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ def parse_chunk_size(self, unreader, data=None):
chunk_size = chunk_size.rstrip(b" \t")
if any(n not in b"0123456789abcdefABCDEF" for n in chunk_size):
raise InvalidChunkSize(chunk_size)
if len(chunk_size) == 0:
raise InvalidChunkSize(chunk_size)
chunk_size = int(chunk_size, 16)

if chunk_size == 0:
Expand Down
7 changes: 7 additions & 0 deletions tests/requests/invalid/chunked_12.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
POST /chunked_no_chunk_size_but_ext HTTP/1.1\r\n
Transfer-Encoding: chunked\r\n
\r\n
;foo=bar\r\n
hello\r\n
0\r\n
\r\n
2 changes: 2 additions & 0 deletions tests/requests/invalid/chunked_12.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from gunicorn.http.errors import InvalidChunkSize
request = InvalidChunkSize
7 changes: 7 additions & 0 deletions tests/requests/invalid/chunked_13.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
POST /chunked_no_chunk_size HTTP/1.1\r\n
Transfer-Encoding: chunked\r\n
\r\n
\r\n
hello\r\n
0\r\n
\r\n
2 changes: 2 additions & 0 deletions tests/requests/invalid/chunked_13.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from gunicorn.http.errors import InvalidChunkSize
request = InvalidChunkSize

0 comments on commit 7f55988

Please sign in to comment.