Merge pull request #98 from kiwix/http_byte_range_fix

Fix HTTP request byte range handling #91
This commit is contained in:
Matthieu Gautier 2017-11-13 14:42:16 +01:00 committed by GitHub
commit 1fcc1ad9d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -676,9 +676,12 @@ static int accessHandlerCallback(void* cls,
int range_start = 0; int range_start = 0;
int range_end = -1; int range_end = -1;
if (acceptRangeHeaderValue != NULL) { if (acceptRangeHeaderValue != NULL) {
// [FIXME] This part is sub-optimal and potentially prone to fail
// because we don't check the string length before using substr
// The `range.length() >= 6` should mitigate the bug but we have to
// rewrite this part.
auto range = std::string(acceptRangeHeaderValue); auto range = std::string(acceptRangeHeaderValue);
if (range.substr(0, 6) == "bytes=") if (range.length() >= 6 && range.substr(0, 6) == "bytes=") {
{
range = range.substr(6); range = range.substr(6);
std::istringstream iss(range); std::istringstream iss(range);
iss >> range_start; iss >> range_start;