From 568c88be3eb00865303b7bda4e6cf178fd8a856c Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Fri, 26 Apr 2024 13:57:00 +0500 Subject: [PATCH] fs: fix out of bounds error when reading chunks --- packages/streamable-fs/src/filehandle.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 { 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);