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

Fixes for chunk table in no-point LAZ files. #151

Merged
merged 2 commits into from
Aug 23, 2023

Conversation

vsautin1
Copy link
Contributor

@vsautin1 vsautin1 commented Aug 21, 2023

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 later seek()performed in writeChunkTable() goes back to the position where chunk_table_offset is to be stored, puts the chunk table header there and then overwrites it with the chunk_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.

@hobu hobu merged commit c9f2814 into hobuinc:master Aug 23, 2023
4 checks passed
@hobu
Copy link
Collaborator

hobu commented Aug 23, 2023

Released with your fixes and a few others. Thanks!

https://github.com/hobuinc/laz-perf/releases/tag/3.4.0

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

Successfully merging this pull request may close these issues.

2 participants