Skip to content

Commit

Permalink
fix bug 53885 (ZipArchive segfault with FL_UNCHANGED on empty archive)
Browse files Browse the repository at this point in the history
  • Loading branch information
smalyshev committed Jan 30, 2011
1 parent d7e9fdc commit f0d42e7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ext/zip/lib/zip_name_locate.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ _zip_name_locate(struct zip *za, const char *fname, int flags,
return -1;
}

if((flags & ZIP_FL_UNCHANGED) && !za->cdir) {
return -1;
}

cmp = (flags & ZIP_FL_NOCASE) ? strcmpi : strcmp;

n = (flags & ZIP_FL_UNCHANGED) ? za->cdir->nentry : za->nentry;
Expand Down
19 changes: 19 additions & 0 deletions ext/zip/tests/bug53885.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
Bug #53885 (ZipArchive segfault with FL_UNCHANGED on empty archive)
--SKIPIF--
<?php
if(!extension_loaded('zip')) die('skip');
?>
--FILE--
<?php
$fname = dirname(__FILE__)."/test53885.zip";
if(file_exists($fname)) unlink($fname);
touch($fname);
$nx=new ZipArchive();
$nx->open($fname);
$nx->locateName("a",ZIPARCHIVE::FL_UNCHANGED);
$nx->statName("a",ZIPARCHIVE::FL_UNCHANGED);
?>
==DONE==
--EXPECTF--
==DONE==

0 comments on commit f0d42e7

Please sign in to comment.