mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-09-03 11:15:20 +02:00
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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user