TC creates invalid ZIPs

Please report only one bug per message!

Moderators: white, Hacker, petermad, Stefan2

Post Reply
User avatar
MarcinW
Power Member
Power Member
Posts: 852
Joined: 2012-01-23, 15:58 UTC
Location: Poland

TC creates invalid ZIPs

Post by *MarcinW »

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
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

AFAIK empty directories are not necessary in ZIPs, structure is built using relative file paths inside of archive. As I see, TC removes file correctly but it doesn't update panel so it is still shows folder with removed file after removing.
User avatar
MarcinW
Power Member
Power Member
Posts: 852
Joined: 2012-01-23, 15:58 UTC
Location: Poland

Post by *MarcinW »

So - because empty directories are not necessary in ZIP files (and other archives?) - there is also a second fix to be done: after deleting last file from the "nonexistent" folder, panel contents should be properly refreshed, i.e. we should be moved one level up in the folder hierarchy.
User avatar
MVV
Power Member
Power Member
Posts: 8702
Joined: 2008-08-03, 12:51 UTC
Location: Russian Federation

Post by *MVV »

i.e. we should be moved one level up in the folder hierarchy
That's what 7-Zip does with such archive. :)
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48083
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by *ghisler(Author) »

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
User avatar
MarcinW
Power Member
Power Member
Posts: 852
Joined: 2012-01-23, 15:58 UTC
Location: Poland

Post by *MarcinW »

Ok, ok. However for consistency and for user convenience, TC could recreate folder structure when repacking a file. And panel should be properly refreshed when deleting last file from the "nonexistent" folder.
User avatar
MarcinW
Power Member
Power Member
Posts: 852
Joined: 2012-01-23, 15:58 UTC
Location: Poland

Post by *MarcinW »

For the sake of completeness: there is also much more trivial way of creating ZIP file without directory structure:
- search for some files with Alt+F7,
- feed results to listbox,
- pack result files to ZIP (with paths).
User avatar
MarcinW
Power Member
Power Member
Posts: 852
Joined: 2012-01-23, 15:58 UTC
Location: Poland

Post by *MarcinW »

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:

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=
Post Reply