mirror of
https://github.com/clangen/musikcube.git
synced 2025-01-01 00:19:20 +00:00
Added some more error-checking around the HttpServer's range header to
ensure we don't try to read invalid offsets.
This commit is contained in:
parent
d8b0aef307
commit
e0bfe2c987
@ -166,11 +166,11 @@ static Range* parseRange(IDataStream* file, const char* range) {
|
||||
|
||||
if (parts.size() == 2) {
|
||||
try {
|
||||
size_t from = std::stoul(boost::algorithm::trim_copy(parts[0]));
|
||||
size_t from = (size_t) std::max(0, std::stoi(boost::algorithm::trim_copy(parts[0])));
|
||||
size_t to = size;
|
||||
|
||||
if (parts.at(1).size()) {
|
||||
to = std::stoul(boost::algorithm::trim_copy(parts[1]));
|
||||
to = (size_t) std::min((int) size, std::stoi(boost::algorithm::trim_copy(parts[1])));
|
||||
}
|
||||
|
||||
if (to > from) {
|
||||
@ -179,10 +179,10 @@ static Range* parseRange(IDataStream* file, const char* range) {
|
||||
result->to = 0;
|
||||
}
|
||||
else if (to >= size) {
|
||||
result->to = size - 1;
|
||||
result->to = (size == 0) ? 0 : size - 1;
|
||||
}
|
||||
else {
|
||||
result->to = to - 1;
|
||||
result->to = (to == 0) ? 0 : to - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user