Skip to content

Commit

Permalink
fix(core): do not read past the end of the offset arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
blacha committed Dec 15, 2023
1 parent 60e9d47 commit 8699bc3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/core/src/tiff.image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,11 @@ export class TiffImage {
}

function getOffset(tiff: Tiff, x: TagOffset | TagInline<number[]>, index: number): number | Promise<number> {
if (index > x.count || index < 0) throw new Error('TagIndex: out of bounds ' + x.id + ' @ ' + index);
if (index < 0) {
throw new Error(`Tiff: ${tiff.source.url.href} out of bounds ${TiffTag[x.id]} index:${index} total:${x.count}`);
}
// Sparse tiffs may not have the full tileWidth * tileHeight in their offset arrays
if (index >= x.count) return 0;
if (x.type === 'inline') return x.value[index] as number;
return getValueAt(tiff, x, index);
}

0 comments on commit 8699bc3

Please sign in to comment.