Skip to content

Commit

Permalink
Merge pull request #1636 from WebFreak001/safety-checks
Browse files Browse the repository at this point in the history
Safety checks in fileserver
  • Loading branch information
s-ludwig committed Nov 27, 2016
2 parents 6805267 + cc581ea commit c6c54ec
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions http/vibe/http/fileserver.d
Original file line number Diff line number Diff line change
Expand Up @@ -322,19 +322,25 @@ private void sendFileImpl(scope HTTPServerRequest req, scope HTTPServerResponse
if (range.canFind(','))
throw new HTTPStatusException(HTTPStatus.notImplemented);
auto s = range.split("-");
if (s.length != 2)
throw new HTTPStatusException(HTTPStatus.badRequest);
// https://tools.ietf.org/html/rfc7233
// Range can be in form "-\d", "\d-" or "\d-\d"
if (s[0].length) {
rangeStart = s[0].to!ulong;
rangeEnd = s[1].length ? s[1].to!ulong : dirent.size;
} else if (s[1].length) {
rangeEnd = dirent.size;
auto len = s[1].to!ulong;
if (len >= rangeEnd)
rangeStart = 0;
else
rangeStart = rangeEnd - len;
} else {
try {
if (s[0].length) {
rangeStart = s[0].to!ulong;
rangeEnd = s[1].length ? s[1].to!ulong : dirent.size;
} else if (s[1].length) {
rangeEnd = dirent.size;
auto len = s[1].to!ulong;
if (len >= rangeEnd)
rangeStart = 0;
else
rangeStart = rangeEnd - len;
} else {
throw new HTTPStatusException(HTTPStatus.badRequest);
}
} catch (ConvException) {
throw new HTTPStatusException(HTTPStatus.badRequest);
}
if (rangeEnd > dirent.size)
Expand Down

0 comments on commit c6c54ec

Please sign in to comment.