TC creates invalid ZIPs
Moderators: Hacker, petermad, Stefan2, white
TC creates invalid ZIPs
Under some circumstances, TC creates an invalid ZIP archive (but with no data loss). Steps to reproduce:
1) Create file "C:\test\file.txt" on your local disk, file may be empty.
2) Select folder "test" and pack it into "test.zip". We get an archive with the following structure: "test.zip\test\file.txt".
3) Go into the archive and press F4 on the "file.txt" - after confirming it will be unpacked to the TEMP folder and opened with the Notepad.
4) Switch from the Notepad to the TC and - in the "test.zip" - delete file "file.txt" and folder "test".
Please note: folder "test" has been removed from the internal ZIP directory (at the end of a ZIP file - see ZIP file format).
5) Now switch to the Notepad, edit file and close Notepad with saving changes.
6) TC informs that file has been changed - repack it into the ZIP file.
7) TC creates again file "test\file.txt" inside "test.zip", but it doesn't recreate folder "test" (which was removed in step 4).
In other words, internal ZIP directory (at the end of our ZIP file) contains now "test\file.txt" record (for file), but doesn't contain "test" record (for folder).
In such way we created an invalid ZIP file, without folder "test", but with a file inside this folder. Now go into "test.zip\test\file.txt" and delete "file.txt" - file seems not to be deleted(!) and refreshing shows, that folder "test" also disappeared (because, in fact, it wasn't existing).
To be fixed: when repacking a file into an archive, make sure that the full folder tree is existing. If not - recreate.
Regards
1) Create file "C:\test\file.txt" on your local disk, file may be empty.
2) Select folder "test" and pack it into "test.zip". We get an archive with the following structure: "test.zip\test\file.txt".
3) Go into the archive and press F4 on the "file.txt" - after confirming it will be unpacked to the TEMP folder and opened with the Notepad.
4) Switch from the Notepad to the TC and - in the "test.zip" - delete file "file.txt" and folder "test".
Please note: folder "test" has been removed from the internal ZIP directory (at the end of a ZIP file - see ZIP file format).
5) Now switch to the Notepad, edit file and close Notepad with saving changes.
6) TC informs that file has been changed - repack it into the ZIP file.
7) TC creates again file "test\file.txt" inside "test.zip", but it doesn't recreate folder "test" (which was removed in step 4).
In other words, internal ZIP directory (at the end of our ZIP file) contains now "test\file.txt" record (for file), but doesn't contain "test" record (for folder).
In such way we created an invalid ZIP file, without folder "test", but with a file inside this folder. Now go into "test.zip\test\file.txt" and delete "file.txt" - file seems not to be deleted(!) and refreshing shows, that folder "test" also disappeared (because, in fact, it wasn't existing).
To be fixed: when repacking a file into an archive, make sure that the full folder tree is existing. If not - recreate.
Regards
- ghisler(Author)
- Site Admin
- Posts: 50386
- Joined: 2003-02-04, 09:46 UTC
- Location: Switzerland
- Contact:
Indeed empty folders are not a requirement in ZIP archives. TC adds them when packing normally so you can remove all files from the folder and still keep the folder itself. But it's not required by the ZIP standard.
Author of Total Commander
https://www.ghisler.com
https://www.ghisler.com
There is also another problem with ZIPs without directory structure: searching for directory names (with Alt+F7) doesn't work as it can be expected.
Below is a test ZIP archive. The structure is:
test.zip\dir1
test.zip\dir1\file1.txt
test.zip\dir2\file2.txt
Now if we go into test.zip and search for "dir" with Alt+F7, we will find "dir1", but we will not find "dir2".
So, as a summary of this thread - three things can be improved:
1) directory structure could be created, when packing with paths to a ZIP archive (after editing a packed file or when adding to the ZIP archive from the panel, after feeding search results to that panel),
2) panel contents could be properly refreshed, after deleting last file from the "nonexistent" directory (for ZIPs created by previous versions of TCMD or by other tools),
3) search algorithm could be improved, to include also "nonexistent" directories (for ZIPs created by previous versions of TCMD or by other tools).
Regards
test.b64:
Below is a test ZIP archive. The structure is:
test.zip\dir1
test.zip\dir1\file1.txt
test.zip\dir2\file2.txt
Now if we go into test.zip and search for "dir" with Alt+F7, we will find "dir1", but we will not find "dir2".
So, as a summary of this thread - three things can be improved:
1) directory structure could be created, when packing with paths to a ZIP archive (after editing a packed file or when adding to the ZIP archive from the panel, after feeding search results to that panel),
2) panel contents could be properly refreshed, after deleting last file from the "nonexistent" directory (for ZIPs created by previous versions of TCMD or by other tools),
3) search algorithm could be improved, to include also "nonexistent" directories (for ZIPs created by previous versions of TCMD or by other tools).
Regards
test.b64:
Code: Select all
MIME-Version: 1.0
Content-Type: application/octet-stream; name="test.zip"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="test.zip"
UEsDBBQAAgAAACcNyUIAAAAAAAAAAAAAAAAFAAAAZGlyMS9QSwMEFAACAAgAKw3JQgAAAAACAAAA
AAAAAA4AAABkaXIxL2ZpbGUxLnR4dAMAUEsDBBQAAgAIAC8NyUIAAAAAAgAAAAAAAAAOAAAAZGly
Mi9maWxlMi50eHQDAFBLAQIUABQAAgAAACcNyUIAAAAAAAAAAAAAAAAFAAAAAAAAAAAAEAAAAAAA
AABkaXIxL1BLAQIUABQAAgAIACsNyUIAAAAAAgAAAAAAAAAOAAAAAAAAAAAAIAAAACMAAABkaXIx
L2ZpbGUxLnR4dFBLAQIUABQAAgAIAC8NyUIAAAAAAgAAAAAAAAAOAAAAAAAAAAAAIAAAAFEAAABk
aXIyL2ZpbGUyLnR4dFBLBQYAAAAAAwADAKsAAAB/AAAAAAA=