Skip to content

Commit b7d6507

Browse files
committed
in gridstore download stream ensure that start is never bigger than end
1 parent 3c9ecc7 commit b7d6507

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

lib/attachments/gridstore-storage.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,27 @@ class GridstoreStorage {
373373
if (streamOptions.end && streamOptions.end > attachmentData.length) {
374374
streamOptions.end = attachmentData.length;
375375
}
376+
377+
// Handle case where start equals or exceeds end
378+
if (streamOptions.start && streamOptions.end && streamOptions.start >= streamOptions.end) {
379+
streamOptions.start = attachmentData.length;
380+
streamOptions.end = attachmentData.length;
381+
}
382+
383+
// Handle case where start equals file length (EOF scenario)
384+
if (streamOptions.start === attachmentData.length && !streamOptions.end) {
385+
streamOptions.end = attachmentData.length;
386+
}
387+
388+
if (streamOptions.end === null || streamOptions.end === undefined) {
389+
// still no stream end, default to length
390+
streamOptions.end = attachmentData.length;
391+
}
392+
393+
if (streamOptions.start > streamOptions.end) {
394+
// Ensure in any case that start is never bigger than end
395+
streamOptions.start = streamOptions.end;
396+
}
376397
}
377398

378399
log.silly(

0 commit comments

Comments
 (0)