Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

fs: fix out of bounds error when reading chunks

Abdullah Atta568c88be3eb0
diff --git a/packages/streamable-fs/src/filehandle.ts b/packages/streamable-fs/src/filehandle.ts
index ec2f8bd95..04f66c8bd 100644
--- a/packages/streamable-fs/src/filehandle.ts
+++ b/packages/streamable-fs/src/filehandle.ts
@@ -71,7 +71,7 @@ export default class FileHandle {
async readChunks(from: number, length: number): Promise<Blob> {
const blobParts: BlobPart[] = [];
- for (let i = from; i < from + length; ++i) {
+ for (let i = from; i < Math.min(from + length, this.file.chunks); ++i) {
const array = await this.readChunk(i);
if (!array) continue;
blobParts.push(array.buffer);