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

Allow opening read-only ZIP files #278

Merged
merged 1 commit into from
Sep 16, 2022
Merged

Allow opening read-only ZIP files #278

merged 1 commit into from
Sep 16, 2022

Conversation

thp
Copy link
Contributor

@thp thp commented Sep 16, 2022

The function zip_open("somefile.zip", 0, 'r'); fails if somefile.zip is read-only.

To test this, just add a call to chmod(ZIPNAME, S_IRUSR); (needs sys/stat.h included) to the end of test_setup() in test/test_read.c.

The reason for this is that 'r' uses this:

zip/src/zip.c

Line 847 in 114d9d4

if (!mz_zip_reader_init_file_v2_rpb(

..which in turn uses this:

zip/src/miniz.h

Line 5999 in 114d9d4

pFile = MZ_FOPEN(pFilename, "r+b");

An fopen() with mode r+ means that it's opened read-write.

This PR fixes it by using mz_zip_reader_init_file_v2() (which opens in rb mode, not r+b mode) when opening files in 'r' mode.

This fix should help with the downstream issue SuperIlu/DOjS#28

@kuba--
Copy link
Owner

kuba-- commented Sep 16, 2022

Thanks

@kuba-- kuba-- merged commit 7a57414 into kuba--:master Sep 16, 2022
@thp thp deleted the thp/readonly-opening branch September 17, 2022 05:39
thabetx pushed a commit to Symbyo360/zip that referenced this pull request Sep 7, 2023
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.

None yet

2 participants