Clamp HTTP response body to the requested range in HTTPFileLoader

A malicious or MITM'd server could send a Content-Range header matching
the requested range but a larger entity body, overflowing the caller's
fixed-size buffer via output.Take. Clamp the copied size to the requested
range.
This commit is contained in:
Henrik Rydgård
2026-08-01 11:57:27 +02:00
parent 5d10f281ef
commit a8195e7ca6
+4 -1
View File
@@ -254,7 +254,10 @@ size_t HTTPFileLoader::ReadAt(s64 absolutePos, size_t bytes, void *data, Flags f
return 0;
}
size_t readBytes = output.size();
// Never trust the entity length: a malicious/MITM'd server can claim a
// matching Content-Range but send a larger body. Clamp to what we
// requested so we can't overflow the caller's fixed-size buffer.
size_t readBytes = std::min(output.size(), (size_t)(absoluteEnd - absolutePos));
output.Take(readBytes, (char *)data);
filepos_ = absolutePos + readBytes;
return readBytes;