Prevent reading beyond end of file (#1626)
Co-authored-by: Erik at Axis <[email protected]>
This commit is contained in:
co-authored by
Erik at Axis
parent
bd1c41a06b
commit
b6f27a0c19
@@ -38,7 +38,8 @@ struct AsyncFileStreamer {
|
|||||||
static void streamFile(uWS::HttpResponse<SSL> *res, AsyncFileReader *asyncFileReader) {
|
static void streamFile(uWS::HttpResponse<SSL> *res, AsyncFileReader *asyncFileReader) {
|
||||||
/* Peek from cache */
|
/* Peek from cache */
|
||||||
std::string_view chunk = asyncFileReader->peek(res->getWriteOffset());
|
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 */
|
/* Request new chunk */
|
||||||
// todo: we need to abort this callback if peer closed!
|
// 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)
|
// 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
|
// 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) {
|
asyncFileReader->request(res->getWriteOffset(), [res, asyncFileReader](std::string_view chunk) {
|
||||||
// check if we were closed in the mean time
|
// check if we were closed in the mean time
|
||||||
//if (us_socket_is_closed()) {
|
//if (us_socket_is_closed()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user