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

Issues when adding an empty directory #756

Closed
pmqs opened this issue Dec 28, 2023 · 4 comments
Closed

Issues when adding an empty directory #756

pmqs opened this issue Dec 28, 2023 · 4 comments
Labels
bug Bug zip ZIP file format

Comments

@pmqs
Copy link
Contributor

pmqs commented Dec 28, 2023

running latest build from the develop branch on Linux

$ minizip -v
minizip-ng 4.0.3 - https://github.com/zlib-ng/minizip-ng
---------------------------------------------------
-v 
Usage: minizip [-x][-d dir|-l|-e][-o][-f][-y][-c cp][-a][-0 to -9][-b|-m|-t][-k 512][-p pwd][-s] file.zip [files]

  -x  Extract files
  -l  List files
  -d  Destination directory
  -e  Erase files
  -o  Overwrite existing files
  -c  File names use cp437 encoding (or specified codepage)
  -a  Append to existing zip file
  -i  Include full path of files
  -f  Follow symbolic links
  -y  Store symbolic links
  -v  Verbose info
  -0  Store only
  -1  Compress faster
  -9  Compress better
  -k  Disk size in KB
  -z  Zip central directory
  -p  Encryption password
  -s  AES encryption
  -b  BZIP2 compression
  -m  LZMA compression
  -n  XZ compression
  -t  ZSTD compression

Create an empty directory & add to a zip with minizip

$ mkdir somedir

$ minizip d.zip somedir
minizip-ng 4.0.3 - https://github.com/zlib-ng/minizip-ng
---------------------------------------------------
d.zip somedir/ 
Archive d.zip

$ echo $?
0

That didn't complain and the exit status was zero.

Let's see what minizip thinks is in the zip file we just created.

$ minizip -l d.zip 
minizip-ng 4.0.3 - https://github.com/zlib-ng/minizip-ng
---------------------------------------------------
-l d.zip 
      Packed     Unpacked Ratio Method   Attribs Date     Time  CRC-32     Name
      ------     -------- ----- ------   ------- ----     ----  ------     ----
Error -107 getting entry info in archive

What about unzip?

$ unzip -lv d.zip 
Archive:  d.zip
warning [d.zip]:  zipfile is empty

Looking inside the zip file, it is indeed an empty zip file with just the EOCD header, That zip file is valid, but not common out in the wild.

$ zipdetails d.zip 

0000 END CENTRAL HEADER    06054B50 (101010256)
0004 Number of this disk   0000 (0)
0006 Central Dir Disk no   0000 (0)
0008 Entries in this disk  0000 (0)
000A Total Entries         0000 (0)
000C Size of Central Dir   00000000 (0)
0010 Offset to Central Dir 00000000 (0)
0014 Comment Length        0000 (0)
#
# Done

Questions & possible issues:

  1. Does minizip support adding directories ?
    If minizip doesn't support adding directories as separate entries in a zip file, the resulting zip file created would be classed as normal behaviour.
  2. The zip file created is valid, but minizip doesn't like it.
    An empty zip file like this is a bit of an edge case, but it feels like a bug
@nmoinvaz
Copy link
Member

Does minizip support adding directories ?

Yes it does. Although, I don't think the ziprw classes don't do it, but an entry can be added using mz_zip_file with the directory name and appropriate file attributes for directories. Usually I think it only adds files and not directory entries. I am open to any PRs that will improve support for empty directories in that class or in the compat class.

The zip file created is valid, but minizip doesn't like it.

It may be an edge case as you said. I think minizip should probably be able to handle it.

@nmoinvaz nmoinvaz added zip ZIP file format bug Bug labels Feb 17, 2024
@nmoinvaz
Copy link
Member

I have added a commit to develop that should add empty directories.

@nmoinvaz
Copy link
Member

nmoinvaz commented Jun 1, 2024

I have discovered that it already did support empty directories in a zip file and my change only made it worse. I am reverting it.

The problem is with the way you are using it.
Your directory structure should look like this:

.
somedir
somedir\emptydir

It would then add emptydir to the zip file.
But if you just tell it to zip up somedir without anything in it, then the zip file will be empty.

@nmoinvaz
Copy link
Member

nmoinvaz commented Jun 1, 2024

I have corrected the issue with it not being able to list empty zip.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug zip ZIP file format
Projects
None yet
Development

No branches or pull requests

2 participants