Fixes for chunk table in no-point LAZ files. #151
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've stumbled on a LAZ file that laz-perf could not open claiming the chunk table is invalid.
Turned out the file contains zero points. The chunk table is there though, the chunk_table_offset is valid and points to the chunk table consisting of just header with count = 0.
The Generating Software in the file header is "LAStools" (maybe it's possible to create such a file with LAStools, idk).
I tried to create a LAZ with no points using LASzip and it produced essentially the same layout, having chunk table with zero entries.
LASzip can open the file with no complaints.
I could not find specs stating exactly what the chunk table must be for a no-points file,. Given that LASzip is fine with the empty chunk table, I think it would be nice to allow user to open such file and read the header data.
I made a simple fix for the above, adding a unit test and the no-point data files for it.
Then I noticed that there already is a unit test called
lazperf_tests.empty_file_write
that writes out a no-point LAZ. I decided to change my unit test to write out an empty temp file and then read it back, and avoid adding the data files for the test.I tried doing that and it did not work.
Turned out the LAZ file produced by
lazperf_tests.empty_file_write
is not valid.It places the chunk table at incorrect location, overlapping with chunk_table_offset space.
This happens because the writer reserves the space for chunk_table_offset by
seek()
ing beyond the current end of file. However if there are no points, then no writes happen at this position, and the file does not actually get extended. The laterseek()
performed inwriteChunkTable()
goes back to the position where chunk_table_offset is to be stored, puts the chunk table header there and then overwrites it with thechunk_table_offset
value.I made a fix for this too (the second commit).
Just in case: I noticed that for a no-point output the laz-perf writer creates a chunk table that actually has 1 entry with count = 0. I don't know what is the LAZ policy regarding empty chunks, so not sure if this is a problem or a feature.