From ed4ab1552410378da634534e9886ee5a09983cee Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Fri, 20 May 2022 22:22:55 -0400 Subject: [PATCH] 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. --- src/physfs_archiver_zip.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/physfs_archiver_zip.c b/src/physfs_archiver_zip.c index 296cf26..5cd657d 100644 --- a/src/physfs_archiver_zip.c +++ b/src/physfs_archiver_zip.c @@ -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);