diff --git a/Readme.md b/Readme.md index ee34fae7..0fe54742 100644 --- a/Readme.md +++ b/Readme.md @@ -145,9 +145,6 @@ http.get(options, function (response) { }) ``` -You can optionally check the buffer lengths & stop downloading the image after a few kilobytes. -**You don't need to download the entire image** - ### Disabling certain image types ```javascript diff --git a/lib/types/utils.ts b/lib/types/utils.ts index b3bcadee..9c74975c 100644 --- a/lib/types/utils.ts +++ b/lib/types/utils.ts @@ -74,12 +74,17 @@ function readBox(input: Uint8Array, offset: number) { } } -export function findBox(input: Uint8Array, boxName: string, offset: number) { - let currentOffset = offset +export function findBox( + input: Uint8Array, + boxName: string, + currentOffset: number, +) { while (currentOffset < input.length) { const box = readBox(input, currentOffset) if (!box) break if (box.name === boxName) return box - currentOffset += box.size + // Fix the infinite loop by ensuring offset always increases + // If box.size is 0, advance by at least 8 bytes (the size of the box header) + currentOffset += box.size > 0 ? box.size : 8 } } diff --git a/package.json b/package.json index b494fe06..73463356 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "image-size", - "version": "2.0.1", + "version": "2.0.2", "description": "get dimensions of any image file", "main": "./dist/index.cjs", "module": "./dist/index.mjs",