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 Windows Timestamps for Alternate Data Streams #837

Merged
merged 5 commits into from
Jan 8, 2025

Conversation

gabriellandau
Copy link
Contributor

Should this target develop or master?

Summary

This PR changes mz_os_get_file_date to use GetFileAttributesExW instead of FindFirstFileW, because FindFirstFileW fails on Windows Alternate Data Streams.

Description

mz_os_get_file_date uses FindFirstFileW, which doesn't support Windows Alternate Data Streams (ADS). The failed return value of mz_os_get_file_date is not checked by mz_zip_writer_add_file. When an ADS is compressed with mz_zip_writer_add_file, the resulting entry has all-zero timestamps. When we attempted to extract this file using various applications (Windows Explorer, 7-Zip, Python), the CRC check would fail. In python, the failure was here. When we commented out that check, the file extracted correctly.

Testing

The old implementation fails the new gtest:

Running main() from C:\git\minizip-ng\test\test_main.cc
Note: Google Test filter = *get_file_date_ads
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from os
[ RUN      ] os.get_file_date_ads
C:\git\minizip-ng\test\test_file.cc(38): error: Expected equality of these values:
  (0)
    Which is: 0
  mz_os_get_file_date(adsName.c_str(), &modified_date, &accessed_date, &creation_date)
    Which is: -104
C:\git\minizip-ng\test\test_file.cc(42): error: Expected: (modified_date) > (0), actual: 0 vs 0
[  FAILED  ] os.get_file_date_ads (2 ms)
[----------] 1 test from os (3 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (3 ms total)
[  PASSED  ] 0 tests.
[  FAILED  ] 1 test, listed below:
[  FAILED  ] os.get_file_date_ads

 1 FAILED TEST

The new implementation passes:

Running main() from C:\git\minizip-ng\test\test_main.cc
Note: Google Test filter = *get_file_date_ads
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from os
[ RUN      ] os.get_file_date_ads
[       OK ] os.get_file_date_ads (1 ms)
[----------] 1 test from os (1 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (2 ms total)
[  PASSED  ] 1 test.

Copy link
Member

@nmoinvaz nmoinvaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just have style changes. Thanks for the unit test.

test/test_file.cc Outdated Show resolved Hide resolved
test/test_file.cc Outdated Show resolved Hide resolved
test/test_file.cc Outdated Show resolved Hide resolved
@nmoinvaz nmoinvaz merged commit 1e973d2 into zlib-ng:develop Jan 8, 2025
28 checks passed
@gabriellandau gabriellandau deleted the fix-windows-ads-timestamps branch January 8, 2025 15:04
@gabriellandau
Copy link
Contributor Author

Thanks @nmoinvaz. When do you think this fix will land in a release? We'd like to get a fix out to a customer if possible.

There have been a bunch of other commits in develop since 4.0.7 too.

@gabriellandau
Copy link
Contributor Author

I see you just released 4.0.8. Thank you.

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