Prevent reading beyond end of file (#1626)
Co-authored-by: Erik at Axis <erik.janssen@axis.com>
This commit is contained in:
@@ -38,7 +38,8 @@ struct AsyncFileStreamer {
|
||||
static void streamFile(uWS::HttpResponse<SSL> *res, AsyncFileReader *asyncFileReader) {
|
||||
/* Peek from cache */
|
||||
std::string_view chunk = asyncFileReader->peek(res->getWriteOffset());
|
||||
if (!chunk.length() || res->tryEnd(chunk, asyncFileReader->getFileSize()).first) {
|
||||
auto remaining_data = r->getFileSize() - res->getWriteOffset();
|
||||
if (!chunk.length() || res->tryEnd(chunk, remaining_data).first) {
|
||||
/* Request new chunk */
|
||||
// todo: we need to abort this callback if peer closed!
|
||||
// this also means Loop::defer needs to support aborting (functions should embedd an atomic boolean abort or something)
|
||||
@@ -50,7 +51,7 @@ struct AsyncFileStreamer {
|
||||
|
||||
// us_socket_up_ref eftersom vi delar ägandeskapet
|
||||
|
||||
if (chunk.length() < asyncFileReader->getFileSize()) {
|
||||
if (chunk.length() < remaining_data) {
|
||||
asyncFileReader->request(res->getWriteOffset(), [res, asyncFileReader](std::string_view chunk) {
|
||||
// check if we were closed in the mean time
|
||||
//if (us_socket_is_closed()) {
|
||||
|
||||
Reference in New Issue
Block a user