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

Fix handling of local file header for 3TZ #173

Merged
merged 3 commits into from
Feb 17, 2025
Merged

Conversation

javagl
Copy link
Contributor

@javagl javagl commented Feb 8, 2025

There have been reports of 3TZ files that could not be read due to improper handling of the "extras" field in local file headers. The 3TZ reading functions simply assumed that the "extras" are at most 48 bytes (and I don't know where this value came from). But certain files that had been accessed with certain tools could contain extras that contained more than 48 bytes (in a "Windows NT Security Descriptor Extra Field", see specs).

The change here removes the assumption of these 48 bytes. The archive functions now explicitly look at the actual size of the extras field in the header, and then use this to compute the offset at which the actual file data can be read.

I'm opening this as a "draft" for now. I'd like to add some tests/specs. But in terms of 3TZ, there currently is zero test coverage, and I don't know how the problematic files had been created, so it's not entirely clear how the test coverage could sensibly be increased here...

@javagl
Copy link
Contributor Author

javagl commented Feb 13, 2025

While creating specs for this, I noticed that there is another hard-wired (wrong) constant of 320 bytes that was carried over from the original implementation, meaning that the functions cannot read 3TZ files that are smaller than 320 bytes (like the one that I just created for the specs 😬 ). I'll add a fix for this as well...

@javagl
Copy link
Contributor Author

javagl commented Feb 13, 2025

... and this fix was pretty trivial: Just don't try to read more than the file size, as in

- const bytesToRead = 320;
+ const bytesToRead = Math.min(320, stat.size);  

I also added some spec files for the 3TZ reading functionality that explicitly covers these corner cases. (There are other specs that causally deal with 3TZ, but that do not cover some of these low-level details)

@javagl
Copy link
Contributor Author

javagl commented Feb 13, 2025

I think that this could be ready for review, but I'll use this state more extensively for tests in the 3d-tiles-validator (c.f. CesiumGS/3d-tiles-validator#331 (comment) ) and if there are any further 3TZ related issues in the tools, I'll fix them as part of this PR.

@javagl
Copy link
Contributor Author

javagl commented Feb 15, 2025

I tested this more extensively, in the context of CesiumGS/3d-tiles-validator#332 , with real-world tilesets that contain (many, huge) 3TZ files, and everything seemed to work properly. So this should be good to go.

@javagl javagl marked this pull request as ready for review February 15, 2025 15:12
@javagl javagl mentioned this pull request Feb 15, 2025
@lilleyse lilleyse merged commit 590ca86 into main Feb 17, 2025
2 checks passed
@lilleyse lilleyse deleted the fix-3tz-file-header-access branch February 17, 2025 14:05
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