Fail make_file_body()'s provider when the file is short (#2566)

make_file_body() measures the file once and that length is already the
response's Content-Length. The provider re-opens the file by path on each
call, so if the file has been truncated since, the read comes up empty and
the provider returned true without writing. write_content_with_progress()
advances its offset only by what was written, so it called the provider
again, got nothing again, and kept spinning until the peer gave up.

Return false instead, as every other failure in this provider does.
This commit is contained in:
Robert Miller authored and GitHub committed 2026-08-26 22:44:04 -04:00
1 parent e96a52e9dd
commit 794a997d8c
2 files changed
+64 -1

No files matched your search

+4 -1
View File
@@ -1523,7 +1523,10 @@ make_file_body(const std::string &filepath) {
auto to_read = (std::min)(sizeof(buf), length);
f.read(buf, static_cast<std::streamsize>(to_read));
auto n = static_cast<size_t>(f.gcount());
if (n == 0) { break; }
// The file is shorter than the size make_file_body() measured, which the
// caller has already committed to as Content-Length. The body cannot be
// completed, so fail as every other error here does.
if (n == 0) { return false; }
if (!sink.write(buf, n)) { return false; }
length -= n;
}