Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to decode tiled GeoTIFF #432

Open
kristoffer-dyrkorn opened this issue Jul 15, 2024 · 2 comments
Open

Unable to decode tiled GeoTIFF #432

kristoffer-dyrkorn opened this issue Jul 15, 2024 · 2 comments

Comments

@kristoffer-dyrkorn
Copy link

kristoffer-dyrkorn commented Jul 15, 2024

It seems geotiff.js 2.1.3 is not able to decode a tiled GeoTIFF file I wanted to parse using node.js (v 22.3.0).

It seems the reason is that the TileByteCounts and TileOffsets arrays in the File Directory object somehow end up having only zero values. And then the decoding of the image tiles fails.

The error occurs when calling the image.readRasters() method - but I suspect the root cause lies in the parsing of the File Directory information.

See attachment for a minimal code example - and data file - that can be used to reproduce the issue.
testcase.zip

@kristoffer-dyrkorn
Copy link
Author

kristoffer-dyrkorn commented Jul 16, 2024

Small update: It seems the two arrays start with zero values but do not have only zero values. I tried using exiftool to verify/read out the File Directory info from the test tiff, and geotiff.js and exiftool produce the same result. So I assume that this is correct. This means the File Directory parsing in tiff.getImage() is correct - and that the error happens in image.readRasters() when using the array values to decode the tiles.

@kristoffer-dyrkorn
Copy link
Author

kristoffer-dyrkorn commented Jul 16, 2024

Have found out more about what happens when the code crashes:

In geotiffimage.js, line 485:

const buffer = tile.data;
const dataView = new DataView(buffer);

...the code creates a dataview that stores 0 bytes (the tile.data array has zero length).

In geotiffimage.js, line 500:

const value = reader.call(dataView, pixelOffset + srcSampleOffsets[si], littleEndian);

...the code tries to read out values from a zero-sized dataview, and this makes it fail.

Could it be that the code should just skip tiles where the TileByteCounts value is zero? Or is the data in the example tiff file inherently wrong? (Both GDAL and QGIS can successfully open the file.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant