Skip to content

web: Cap growing static files at Content-Length#3693

Open
Sanjays2402 wants to merge 1 commit into
tornadoweb:masterfrom
Sanjays2402:fix/static-file-growth-content-length
Open

web: Cap growing static files at Content-Length#3693
Sanjays2402 wants to merge 1 commit into
tornadoweb:masterfrom
Sanjays2402:fix/static-file-growth-content-length

Conversation

@Sanjays2402

Copy link
Copy Markdown

Fixes #2769.

StaticFileHandler calculates Content-Length before streaming but reads the file to EOF, so a file that grows during the request overruns the advertised length and closes the connection. Limit emitted chunks to the calculated response length while preserving the existing get_content(..., end=None) override contract.

The live-server regression grows the file between sizing and streaming; it fails with HTTPOutputError before the fix and passes after it. StaticFileTest passes all 34 tests, and Black, flake8, and mypy (Linux/Windows) pass on both changed files. The full local Python 3.14 suite has one unrelated baseline failure in test_no_open_redirect.

StaticFileHandler calculated Content-Length before streaming, but its
content iterator read to EOF. If the file grew between those operations,
the response exceeded its advertised length and the connection closed.

Limit emitted chunks to the calculated response length while preserving
the get_content override contract. Add a live-server regression test.

Fixes tornadoweb#2769
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

StaticFileHandler fails when the underlying file is enlarged when reading.

1 participant