Oops, don't try to read past end of file.

This commit is contained in:
Unknown W. Brackets 2014-11-24 00:19:13 -08:00
parent 4e11f7c182
commit 49a5394b93

View File

@ -286,7 +286,7 @@ void HTTPFileLoader::Seek(s64 absolutePos) {
}
size_t HTTPFileLoader::ReadAt(s64 absolutePos, size_t bytes, void *data) {
s64 absoluteEnd = absolutePos + bytes;
s64 absoluteEnd = std::min(absolutePos + (s64)bytes, filesize_);
// TODO: Keepalive, etc.
client_.Connect();
@ -319,7 +319,11 @@ size_t HTTPFileLoader::ReadAt(s64 absolutePos, size_t bytes, void *data) {
if (sscanf(header.c_str(), "Content-Range: bytes %lld-%lld/%lld", &first, &last, &total) >= 2) {
if (first == absolutePos && last == absoluteEnd - 1) {
supportedResponse = true;
} else {
ERROR_LOG(LOADER, "Unexpected HTTP range: got %lld-%lld, wanted %lld-%lld.", first, last, absolutePos, absoluteEnd - 1);
}
} else {
ERROR_LOG(LOADER, "Unexpected HTTP range response: %s", header.c_str());
}
}
}