zip: workaround Windows Explorer bug.

If you edit a zip file with Windows Explorer, it will rewrite the entire
central directory, setting all files version_needed field to 2.0/MS-DOS,
but it won't touch files that it doesn't plan to alter, so you might end
up with a local header that doesn't match the central directory details.

We aren't currently using the version_needed information, so now we just
favor the local header's copy of it in case we ever need it, and don't
complain if the central directory doesn't match.

Fixes #24.
This commit is contained in:
Ryan C. Gordon 2022-05-20 22:22:55 -04:00
parent 48e7c2e3af
commit ed4ab15524
No known key found for this signature in database
GPG Key ID: FA148B892AB48044
1 changed files with 4 additions and 1 deletions

View File

@ -833,7 +833,10 @@ static int zip_parse_local(PHYSFS_Io *io, ZIPentry *entry)
BAIL_IF_ERRPASS(!readui32(io, &ui32), 0);
BAIL_IF(ui32 != ZIP_LOCAL_FILE_SIG, PHYSFS_ERR_CORRUPT, 0);
BAIL_IF_ERRPASS(!readui16(io, &ui16), 0);
BAIL_IF(ui16 != entry->version_needed, PHYSFS_ERR_CORRUPT, 0);
/* Windows Explorer might rewrite the entire central directory, setting
this field to 2.0/MS-DOS for all files, so favor the local version,
which it leaves intact if it didn't alter that specific file. */
entry->version_needed = ui16;
BAIL_IF_ERRPASS(!readui16(io, &ui16), 0); /* general bits. */
BAIL_IF_ERRPASS(!readui16(io, &ui16), 0);
BAIL_IF(ui16 != entry->compression_method, PHYSFS_ERR_CORRUPT, 0);