Fix case where zip file consists of zero entries. Reported broken by François Simon. Add test case for it. --HG-- branch : HEAD
diff --git a/THANKS b/THANKS index f23d9af..568aae5 100644 --- a/THANKS +++ b/THANKS
@@ -5,6 +5,7 @@ Alexander Galanin <al@galanin.nnov.ru> Andrew Brampton <brampton@gmail.com> +François Simon <AT.GFI.Francois.SIMON@sesam-vitale.fr> Heiko Hund <heiko@ist.eigentlich.net> Joel Ebrahimi <joel.ebrahimi@gmail.com> Jono Spiro <jono.spiro@gmail.com>
diff --git a/lib/zip_open.c b/lib/zip_open.c index 015c91e..5fcf8e7 100644 --- a/lib/zip_open.c +++ b/lib/zip_open.c
@@ -257,7 +257,7 @@ left = cd->size; i=0; - do { + while (i<cd->nentry && left > 0) { if ((_zip_dirent_read(cd->entry+i, fp, bufp, &left, 0, error)) < 0) { cd->nentry = i; _zip_cdir_free(cd); @@ -274,8 +274,7 @@ return NULL; } } - } while (i<cd->nentry && left > 0); - + } cd->nentry = i; return cd;
diff --git a/regress/CMakeLists.txt b/regress/CMakeLists.txt index 82bc870..cd1bc71 100644 --- a/regress/CMakeLists.txt +++ b/regress/CMakeLists.txt
@@ -22,6 +22,7 @@ SET(EXTRA_TESTS open_cons_extrabytes.test + open_empty.test open_extrabytes.test open_new_but_exists.test open_new_ok.test
diff --git a/regress/Makefile.am b/regress/Makefile.am index 6912213..8c5dacc 100644 --- a/regress/Makefile.am +++ b/regress/Makefile.am
@@ -31,6 +31,7 @@ testchangedlocal.zip \ testcomment.zip \ testcommentremoved.zip \ + testempty.zip \ testextrabytes.zip \ testfile.txt \ testfile.zip \ @@ -54,6 +55,7 @@ get_comment.test \ name_locate.test \ open_cons_extrabytes.test \ + open_empty.test \ open_extrabytes.test \ open_many_ok.test \ open_new_but_exists.test \
diff --git a/regress/open_empty.test b/regress/open_empty.test new file mode 100644 index 0000000..250bc40 --- /dev/null +++ b/regress/open_empty.test
@@ -0,0 +1,6 @@ +# zip_open: file contains no entry, but is valid +program tryopen +file testempty.zip testempty.zip testempty.zip +args testempty.zip +return 0 +stdout opening `testempty.zip' succeeded, 0 entries
diff --git a/regress/testempty.zip b/regress/testempty.zip new file mode 100644 index 0000000..15cb0ec --- /dev/null +++ b/regress/testempty.zip Binary files differ