diff options
| author | Ondřej Surý <ondrej@sury.org> | 2010-01-07 13:31:53 +0100 |
|---|---|---|
| committer | Ondřej Surý <ondrej@sury.org> | 2010-01-07 13:31:53 +0100 |
| commit | 0fab6db7cac8d2be99579dd049f812a8ff98e74f (patch) | |
| tree | 91f01b0d06916c78262404096bfd466b8e95e5b5 /ext/zip | |
| parent | d3a8757891280dc6650ca7eead67830c794b0e7b (diff) | |
| download | php-0fab6db7cac8d2be99579dd049f812a8ff98e74f.tar.gz | |
Imported Upstream version 5.3.1upstream/5.3.1
Diffstat (limited to 'ext/zip')
49 files changed, 187 insertions, 86 deletions
diff --git a/ext/zip/config.m4 b/ext/zip/config.m4 index 4ee9105e7..7b2cf03f0 100644 --- a/ext/zip/config.m4 +++ b/ext/zip/config.m4 @@ -1,5 +1,5 @@ dnl -dnl $Id: config.m4,v 1.8.2.3.2.6 2008/08/08 09:47:15 pajoye Exp $ +dnl $Id: config.m4 264447 2008-08-08 09:47:15Z pajoye $ dnl PHP_ARG_ENABLE(zip, for zip archive read/writesupport, diff --git a/ext/zip/config.w32 b/ext/zip/config.w32 index 53078fd2c..a06ee9385 100644 --- a/ext/zip/config.w32 +++ b/ext/zip/config.w32 @@ -1,4 +1,4 @@ -// $Id: config.w32,v 1.1.2.1.2.6 2008/08/07 23:24:11 pajoye Exp $ +// $Id: config.w32 264425 2008-08-07 23:24:11Z pajoye $ // vim:ft=javascript ARG_ENABLE("zip", "ZIP support", "yes"); diff --git a/ext/zip/examples/im.php b/ext/zip/examples/im.php index a922ab263..efd025fd5 100644 --- a/ext/zip/examples/im.php +++ b/ext/zip/examples/im.php @@ -1,5 +1,5 @@ <?php -/* $Id: im.php,v 1.1.4.1 2008/05/21 09:27:41 pajoye Exp $ */ +/* $Id: im.php 260091 2008-05-21 09:27:41Z pajoye $ */ $im = imagecreatefromgif('zip://' . dirname(__FILE__) . '/test_im.zip#pear_item.gif'); imagepng($im, 'a.png'); diff --git a/ext/zip/examples/odt.php b/ext/zip/examples/odt.php index 3d1a4b918..ac175eb91 100644 --- a/ext/zip/examples/odt.php +++ b/ext/zip/examples/odt.php @@ -1,5 +1,5 @@ <?php -/* $Id: odt.php,v 1.1.4.1 2008/05/21 09:27:41 pajoye Exp $ */ +/* $Id: odt.php 260091 2008-05-21 09:27:41Z pajoye $ */ $reader = new XMLReader(); $reader->open('zip://' . dirname(__FILE__) . '/test.odt#meta.xml'); diff --git a/ext/zip/lib/zip_close.c b/ext/zip/lib/zip_close.c index d9fc6eea4..bc640c77b 100644 --- a/ext/zip/lib/zip_close.c +++ b/ext/zip/lib/zip_close.c @@ -175,6 +175,7 @@ zip_close(struct zip *za) de.filename = strdup("-"); de.filename_len = 1; cd->entry[j].filename = "-"; + cd->entry[j].filename_len = 1; } else { de.filename = strdup(za->cdir->entry[i].filename); @@ -195,13 +196,15 @@ zip_close(struct zip *za) error = 1; break; } + memcpy(cd->entry+j, za->cdir->entry+i, sizeof(cd->entry[j])); + if (de.bitflags & ZIP_GPBF_DATA_DESCRIPTOR) { de.crc = za->cdir->entry[i].crc; de.comp_size = za->cdir->entry[i].comp_size; de.uncomp_size = za->cdir->entry[i].uncomp_size; de.bitflags &= ~ZIP_GPBF_DATA_DESCRIPTOR; - } - memcpy(cd->entry+j, za->cdir->entry+i, sizeof(cd->entry[j])); + cd->entry[j].bitflags &= ~ZIP_GPBF_DATA_DESCRIPTOR; + } } if (za->entry[i].ch_filename) { @@ -229,11 +232,10 @@ zip_close(struct zip *za) zs = NULL; if (!ZIP_ENTRY_DATA_CHANGED(za->entry+i)) { - if ((zs=zip_source_zip(za, za, i, ZIP_FL_RECOMPRESS, 0, -1)) - == NULL) { - error = 1; - break; - } + if ((zs=zip_source_zip(za, za, i, ZIP_FL_RECOMPRESS, 0, -1)) == NULL) { + error = 1; + break; + } } if (add_data(za, zs ? zs : za->entry[i].source, &de, out) < 0) { @@ -286,27 +288,27 @@ zip_close(struct zip *za) return -1; } - if (za->zp) { - fclose(za->zp); - za->zp = NULL; - reopen_on_error = 1; + if (za->zp) { + fclose(za->zp); + za->zp = NULL; + reopen_on_error = 1; } if (_zip_rename(temp, za->zn) != 0) { - _zip_error_set(&za->error, ZIP_ER_RENAME, errno); - remove(temp); - free(temp); - if (reopen_on_error) { - /* ignore errors, since we're already in an error case */ - za->zp = fopen(za->zn, "rb"); + _zip_error_set(&za->error, ZIP_ER_RENAME, errno); + remove(temp); + free(temp); + if (reopen_on_error) { + /* ignore errors, since we're already in an error case */ + za->zp = fopen(za->zn, "rb"); + } + return -1; } - return -1; - } mask = umask(0); umask(mask); chmod(za->zn, 0666&~mask); _zip_free(za); - free(temp); + free(temp); return 0; } diff --git a/ext/zip/lib/zip_fclose.c b/ext/zip/lib/zip_fclose.c index 6bf697301..8f062d9d0 100644 --- a/ext/zip/lib/zip_fclose.c +++ b/ext/zip/lib/zip_fclose.c @@ -49,13 +49,13 @@ zip_fclose(struct zip_file *zf) free(zf->buffer); free(zf->zstr); if (zf->za) { - for (i=0; i<zf->za->nfile; i++) { - if (zf->za->file[i] == zf) { - zf->za->file[i] = zf->za->file[zf->za->nfile-1]; - zf->za->nfile--; - break; - } - } + for (i=0; i<zf->za->nfile; i++) { + if (zf->za->file[i] == zf) { + zf->za->file[i] = zf->za->file[zf->za->nfile-1]; + zf->za->nfile--; + break; + } + } } ret = 0; diff --git a/ext/zip/lib/zip_fread.c b/ext/zip/lib/zip_fread.c index 1c0c8ac63..c0b71b861 100644 --- a/ext/zip/lib/zip_fread.c +++ b/ext/zip/lib/zip_fread.c @@ -41,7 +41,7 @@ ZIP_EXTERN(ssize_t) zip_fread(struct zip_file *zf, void *outbuf, size_t toread) { int ret; - size_t out_before, len; + size_t out_before, len; int i; if (!zf) @@ -63,7 +63,7 @@ zip_fread(struct zip_file *zf, void *outbuf, size_t toread) } return 0; } - + if ((zf->flags & ZIP_ZF_DECOMP) == 0) { ret = _zip_file_fillbuf(outbuf, toread, zf); if (ret > 0) { @@ -83,15 +83,26 @@ zip_fread(struct zip_file *zf, void *outbuf, size_t toread) ret = inflate(zf->zstr, Z_SYNC_FLUSH); switch (ret) { - case Z_OK: case Z_STREAM_END: + zf->flags |= ZIP_ZF_EOF; + + case Z_OK: + /* all ok */ /* Z_STREAM_END probably won't happen, since we didn't have a header */ len = zf->zstr->total_out - out_before; if (len >= zf->bytes_left || len >= toread) { - if (zf->flags & ZIP_ZF_CRC) - zf->crc = crc32(zf->crc, (Bytef *)outbuf, len); + if (zf->flags & ZIP_ZF_CRC) { + zf->crc = crc32(zf->crc, (Bytef *)outbuf, len); + if (zf->flags & ZIP_ZF_EOF == 1) { + if (zf->crc != zf->crc_orig) { + _zip_error_set(&zf->error, ZIP_ER_CRC, 0); + return -1; + } + + } + } zf->bytes_left -= len; return len; } diff --git a/ext/zip/lib/zip_get_archive_comment.c b/ext/zip/lib/zip_get_archive_comment.c index fe97e6e8c..ed1324fd5 100644 --- a/ext/zip/lib/zip_get_archive_comment.c +++ b/ext/zip/lib/zip_get_archive_comment.c @@ -42,11 +42,11 @@ zip_get_archive_comment(struct zip *za, int *lenp, int flags) { if ((flags & ZIP_FL_UNCHANGED) || (za->ch_comment_len == -1)) { - if (za->cdir) { - if (lenp != NULL) - *lenp = za->cdir->comment_len; - return za->cdir->comment; - } + if (za->cdir) { + if (lenp != NULL) + *lenp = za->cdir->comment_len; + return za->cdir->comment; + } else { if (lenp != NULL) *lenp = -1; diff --git a/ext/zip/lib/zip_open.c b/ext/zip/lib/zip_open.c index dbab6ec4a..e3840197d 100644 --- a/ext/zip/lib/zip_open.c +++ b/ext/zip/lib/zip_open.c @@ -75,9 +75,10 @@ zip_open(const char *fn, int flags, int *zep) if (!(flags & ZIP_OVERWRITE)) { return NULL; } - + case 0: return _zip_allocate_new(fn, zep); + default: break; } diff --git a/ext/zip/php_zip.c b/ext/zip/php_zip.c index 983aa5949..ab2c4e7a7 100644 --- a/ext/zip/php_zip.c +++ b/ext/zip/php_zip.c @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_zip.c,v 1.1.2.38.2.29 2009/02/24 23:55:14 iliaa Exp $ */ +/* $Id: php_zip.c 276389 2009-02-24 23:55:14Z iliaa $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -2674,7 +2674,7 @@ static PHP_MINFO_FUNCTION(zip) php_info_print_table_start(); php_info_print_table_row(2, "Zip", "enabled"); - php_info_print_table_row(2, "Extension Version","$Id: php_zip.c,v 1.1.2.38.2.29 2009/02/24 23:55:14 iliaa Exp $"); + php_info_print_table_row(2, "Extension Version","$Id: php_zip.c 276389 2009-02-24 23:55:14Z iliaa $"); php_info_print_table_row(2, "Zip version", PHP_ZIP_VERSION_STRING); php_info_print_table_row(2, "Libzip version", "0.9.0"); diff --git a/ext/zip/php_zip.h b/ext/zip/php_zip.h index 7a2774db0..e75c11814 100644 --- a/ext/zip/php_zip.h +++ b/ext/zip/php_zip.h @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_zip.h,v 1.10.2.3.2.10 2008/12/31 11:15:47 sebastian Exp $ */ +/* $Id: php_zip.h 272370 2008-12-31 11:15:49Z sebastian $ */ #ifndef PHP_ZIP_H #define PHP_ZIP_H diff --git a/ext/zip/tests/bug11216.phpt b/ext/zip/tests/bug11216.phpt index 4c6efa6cc..576e321b1 100644 --- a/ext/zip/tests/bug11216.phpt +++ b/ext/zip/tests/bug11216.phpt @@ -2,7 +2,7 @@ Bug #11216 (::addEmptyDir() crashes when the directory already exists) --SKIPIF-- <?php -/* $Id: bug11216.phpt,v 1.1.2.2.2.2 2009/01/08 22:03:32 tony2001 Exp $ */ +/* $Id: bug11216.phpt 273126 2009-01-08 22:03:32Z tony2001 $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- diff --git a/ext/zip/tests/bug14962.phpt b/ext/zip/tests/bug14962.phpt index 5cecbae30..5193c0469 100644 --- a/ext/zip/tests/bug14962.phpt +++ b/ext/zip/tests/bug14962.phpt @@ -2,7 +2,7 @@ Bug #14962 (::extractTo second argument is not really optional) --SKIPIF-- <?php -/* $Id: bug14962.phpt,v 1.1.2.2 2008/11/12 11:41:21 pajoye Exp $ */ +/* $Id: bug14962.phpt 268855 2008-11-12 11:41:21Z pajoye $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- diff --git a/ext/zip/tests/bug38943.phpt b/ext/zip/tests/bug38943.phpt index 1fbfdaa67..856818275 100644 --- a/ext/zip/tests/bug38943.phpt +++ b/ext/zip/tests/bug38943.phpt @@ -2,7 +2,7 @@ #38943, properties in extended class cannot be set (< 5.3) --SKIPIF-- <?php -/* $Id: bug38943.phpt,v 1.1.2.2.2.2 2008/05/21 09:27:41 pajoye Exp $ */ +/* $Id: bug38943.phpt 260091 2008-05-21 09:27:41Z pajoye $ */ if(!extension_loaded('zip')) die('skip'); if (!defined('PHP_VERSION_MAJOR')) die('skip'); ?> diff --git a/ext/zip/tests/bug38943_2.phpt b/ext/zip/tests/bug38943_2.phpt index b1a48f81a..0045f0d1c 100644 --- a/ext/zip/tests/bug38943_2.phpt +++ b/ext/zip/tests/bug38943_2.phpt @@ -2,7 +2,7 @@ #38943, properties in extended class cannot be set (5.3) --SKIPIF-- <?php -/* $Id: bug38943_2.phpt,v 1.1.2.2 2008/11/12 17:16:51 felipe Exp $ */ +/* $Id: bug38943_2.phpt 268872 2008-11-12 17:16:51Z felipe $ */ if(!extension_loaded('zip')) die('skip'); if (version_compare(PHP_VERSION, "5.3", "<")) die('skip test for5.3+ only'); ?> diff --git a/ext/zip/tests/bug47667.phpt b/ext/zip/tests/bug47667.phpt index 3b985a3cf..d0a4566f2 100644 --- a/ext/zip/tests/bug47667.phpt +++ b/ext/zip/tests/bug47667.phpt @@ -2,7 +2,7 @@ Bug #47667 (ZipArchive::OVERWRITE seems to have no effect) --SKIPIF-- <?php -/* $Id: bug47667.phpt,v 1.1.2.2 2009/03/16 10:19:43 mkoppanen Exp $ */ +/* $Id: bug47667.phpt 277253 2009-03-16 10:19:43Z mkoppanen $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- diff --git a/ext/zip/tests/bug49072.phpt b/ext/zip/tests/bug49072.phpt new file mode 100644 index 000000000..04bd06e4a --- /dev/null +++ b/ext/zip/tests/bug49072.phpt @@ -0,0 +1,24 @@ +--TEST-- +Bug #49072 (feof never returns true for damaged file in zip) +--SKIPIF-- +<?php +/* $Id$ */ +if(!extension_loaded('zip')) die('skip'); +?> +--FILE-- +<?php +$f = dirname(__FILE__) . '/bug49072.zip'; +$o = new ZipArchive(); +if (! $o->open($f, ZipArchive::CHECKCONS)) { + exit ('error can\'t open'); +} +$r = $o->getStream('file1'); // this file has a wrong crc +if (!$r)die('failed to open a stream for file1'); +$s = ''; +while (! feof($r)) { + $s .= fread($r,1024); +} +?> +--EXPECTF-- + +Warning: fread(): Zip stream error: CRC error in %s on line %d diff --git a/ext/zip/tests/bug49072.zip b/ext/zip/tests/bug49072.zip Binary files differnew file mode 100644 index 000000000..16bbcd011 --- /dev/null +++ b/ext/zip/tests/bug49072.zip diff --git a/ext/zip/tests/bug7214.phpt b/ext/zip/tests/bug7214.phpt index bcf04deed..061e7e4cd 100644 --- a/ext/zip/tests/bug7214.phpt +++ b/ext/zip/tests/bug7214.phpt @@ -2,7 +2,7 @@ Bug #7214 (zip_entry_read() binary safe) --SKIPIF-- <?php -/* $Id: bug7214.phpt,v 1.1.2.1.2.1 2008/05/21 09:27:41 pajoye Exp $ */ +/* $Id: bug7214.phpt 260091 2008-05-21 09:27:41Z pajoye $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- diff --git a/ext/zip/tests/bug7658.phpt b/ext/zip/tests/bug7658.phpt index 3746862ef..267d8ff62 100644 --- a/ext/zip/tests/bug7658.phpt +++ b/ext/zip/tests/bug7658.phpt @@ -2,7 +2,7 @@ Bug #7658 (modify archive with general bit flag 3 set) --SKIPIF-- <?php -/* $Id: bug7658.phpt,v 1.1.2.2.2.2 2008/08/30 16:24:33 pajoye Exp $ */ +/* $Id: bug7658.phpt 265669 2008-08-30 16:24:33Z pajoye $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- diff --git a/ext/zip/tests/bug8009.phpt b/ext/zip/tests/bug8009.phpt index 9168d7369..8fcfbd9d3 100644 --- a/ext/zip/tests/bug8009.phpt +++ b/ext/zip/tests/bug8009.phpt @@ -2,7 +2,7 @@ Bug #8009 (cannot add again same entry to an archive) --SKIPIF-- <?php -/* $Id: bug8009.phpt,v 1.1.2.1.2.1 2008/05/21 09:27:41 pajoye Exp $ */ +/* $Id: bug8009.phpt 260091 2008-05-21 09:27:41Z pajoye $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- diff --git a/ext/zip/tests/bug8700.phpt b/ext/zip/tests/bug8700.phpt index e36519ee4..c00e76355 100644 --- a/ext/zip/tests/bug8700.phpt +++ b/ext/zip/tests/bug8700.phpt @@ -2,7 +2,7 @@ Bug #8700 (getFromIndex(0) fails) --SKIPIF-- <?php -/* $Id: bug8700.phpt,v 1.1.2.3.2.1 2008/05/21 09:27:41 pajoye Exp $ */ +/* $Id: bug8700.phpt 260091 2008-05-21 09:27:41Z pajoye $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- diff --git a/ext/zip/tests/oo_addemptydir.phpt b/ext/zip/tests/oo_addemptydir.phpt index e2d2373c3..0a051894b 100644 --- a/ext/zip/tests/oo_addemptydir.phpt +++ b/ext/zip/tests/oo_addemptydir.phpt @@ -2,7 +2,7 @@ ziparchive::addEmptyDir --SKIPIF-- <?php -/* $Id: oo_addemptydir.phpt,v 1.1.2.2.2.1 2008/05/21 09:27:41 pajoye Exp $ */ +/* $Id: oo_addemptydir.phpt 260091 2008-05-21 09:27:41Z pajoye $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- diff --git a/ext/zip/tests/oo_addfile.phpt b/ext/zip/tests/oo_addfile.phpt index 17b2fb466..83bfda5ab 100644 --- a/ext/zip/tests/oo_addfile.phpt +++ b/ext/zip/tests/oo_addfile.phpt @@ -2,7 +2,7 @@ ziparchive::addFile() function --SKIPIF-- <?php -/* $Id: oo_addfile.phpt,v 1.1.2.1.2.1 2008/05/21 09:27:41 pajoye Exp $ */ +/* $Id: oo_addfile.phpt 260091 2008-05-21 09:27:41Z pajoye $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- diff --git a/ext/zip/tests/oo_close.phpt b/ext/zip/tests/oo_close.phpt index b5a4dacd0..4301447a7 100644 --- a/ext/zip/tests/oo_close.phpt +++ b/ext/zip/tests/oo_close.phpt @@ -2,7 +2,7 @@ zip::close() function --SKIPIF-- <?php -/* $Id: oo_close.phpt,v 1.1.4.1 2008/05/21 09:27:41 pajoye Exp $ */ +/* $Id: oo_close.phpt 260091 2008-05-21 09:27:41Z pajoye $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- diff --git a/ext/zip/tests/oo_delete.phpt b/ext/zip/tests/oo_delete.phpt index 8b608927b..68085054a 100644 --- a/ext/zip/tests/oo_delete.phpt +++ b/ext/zip/tests/oo_delete.phpt @@ -2,7 +2,7 @@ Delete entries --SKIPIF-- <?php -/* $Id: oo_delete.phpt,v 1.1.4.3 2008/08/30 23:55:04 pajoye Exp $ */ +/* $Id: oo_delete.phpt 265694 2008-08-30 23:55:04Z pajoye $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- diff --git a/ext/zip/tests/oo_ext_zip.phpt b/ext/zip/tests/oo_ext_zip.phpt index 93fb3cce9..c76e96f43 100644 --- a/ext/zip/tests/oo_ext_zip.phpt +++ b/ext/zip/tests/oo_ext_zip.phpt @@ -2,7 +2,7 @@ Extending Zip class and array property --SKIPIF-- <?php -/* $Id: oo_ext_zip.phpt,v 1.1.4.1 2008/05/21 09:27:41 pajoye Exp $ */ +/* $Id: oo_ext_zip.phpt 260091 2008-05-21 09:27:41Z pajoye $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- diff --git a/ext/zip/tests/oo_extract.phpt b/ext/zip/tests/oo_extract.phpt index a83d26fe9..05d932420 100644 --- a/ext/zip/tests/oo_extract.phpt +++ b/ext/zip/tests/oo_extract.phpt @@ -2,7 +2,7 @@ extractTo --SKIPIF-- <?php -/* $Id: oo_extract.phpt,v 1.2.2.2.2.1 2008/05/21 09:27:41 pajoye Exp $ */ +/* $Id: oo_extract.phpt 260091 2008-05-21 09:27:41Z pajoye $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- diff --git a/ext/zip/tests/oo_getcomment.phpt b/ext/zip/tests/oo_getcomment.phpt index 5a71e7556..7044be160 100644 --- a/ext/zip/tests/oo_getcomment.phpt +++ b/ext/zip/tests/oo_getcomment.phpt @@ -2,7 +2,7 @@ getComment --SKIPIF-- <?php -/* $Id: oo_getcomment.phpt,v 1.1.2.3.2.1 2008/05/21 09:27:41 pajoye Exp $ */ +/* $Id: oo_getcomment.phpt 260091 2008-05-21 09:27:41Z pajoye $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- diff --git a/ext/zip/tests/oo_getnameindex.phpt b/ext/zip/tests/oo_getnameindex.phpt index e012c20dd..7b70f38c6 100644 --- a/ext/zip/tests/oo_getnameindex.phpt +++ b/ext/zip/tests/oo_getnameindex.phpt @@ -2,7 +2,7 @@ getNameIndex --SKIPIF-- <?php -/* $Id: oo_getnameindex.phpt,v 1.1.2.2.2.1 2008/05/21 09:27:41 pajoye Exp $ */ +/* $Id: oo_getnameindex.phpt 260091 2008-05-21 09:27:41Z pajoye $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- diff --git a/ext/zip/tests/oo_getstatusstring.phpt b/ext/zip/tests/oo_getstatusstring.phpt new file mode 100644 index 000000000..efd19e318 --- /dev/null +++ b/ext/zip/tests/oo_getstatusstring.phpt @@ -0,0 +1,28 @@ +--TEST-- +This test will test getStatusString method in ZipArchive +--CREDITS-- +Ole-Petter Wikene <olepw@redpill-linpro.com> +#PHPTestFest2009 Norway 2009-06-09 \o/ +--SKIPIF-- +<?php if (!extension_loaded("zip")) { echo "skip extension not available"; } ?> +--FILE-- +<?php + +$dirname = dirname(__FILE__) . '/'; +$arch = new ZipArchive; +$arch->open($dirname.'foo.zip',ZIPARCHIVE::CREATE); +var_dump($arch->getStatusString()); +//delete an index that does not exist - trigger error +$arch->deleteIndex(2); +var_dump($arch->getStatusString()); +$arch->close(); + +?> +--CLEAN-- +<?php +unlink($dirname.'foo.zip'); +?> +--EXPECT-- +string(8) "No error" +string(16) "Invalid argument" + diff --git a/ext/zip/tests/oo_namelocate.phpt b/ext/zip/tests/oo_namelocate.phpt index a4ff384ee..579a00952 100644 --- a/ext/zip/tests/oo_namelocate.phpt +++ b/ext/zip/tests/oo_namelocate.phpt @@ -2,7 +2,7 @@ Locate entries by name --SKIPIF-- <?php -/* $Id: oo_namelocate.phpt,v 1.1.2.2.2.1 2008/05/21 09:27:41 pajoye Exp $ */ +/* $Id: oo_namelocate.phpt 260091 2008-05-21 09:27:41Z pajoye $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- diff --git a/ext/zip/tests/oo_open.phpt b/ext/zip/tests/oo_open.phpt index 6a04351c8..e8acad0a0 100644 --- a/ext/zip/tests/oo_open.phpt +++ b/ext/zip/tests/oo_open.phpt @@ -2,7 +2,7 @@ zip::open() function --SKIPIF-- <?php -/* $Id: oo_open.phpt,v 1.1.4.1 2008/05/21 09:27:41 pajoye Exp $ */ +/* $Id: oo_open.phpt 260091 2008-05-21 09:27:41Z pajoye $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- diff --git a/ext/zip/tests/oo_properties.phpt b/ext/zip/tests/oo_properties.phpt index c07fd0012..b47154c2d 100644 --- a/ext/zip/tests/oo_properties.phpt +++ b/ext/zip/tests/oo_properties.phpt @@ -2,7 +2,7 @@ ziparchive::properties isset()/empty() checks --SKIPIF-- <?php -/* $Id: oo_properties.phpt,v 1.1.2.4.2.3 2009/01/08 22:03:32 tony2001 Exp $ */ +/* $Id: oo_properties.phpt 273126 2009-01-08 22:03:32Z tony2001 $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- diff --git a/ext/zip/tests/oo_rename.phpt b/ext/zip/tests/oo_rename.phpt index 5c619aa82..aa0a88658 100644 --- a/ext/zip/tests/oo_rename.phpt +++ b/ext/zip/tests/oo_rename.phpt @@ -2,7 +2,7 @@ Rename entries --SKIPIF-- <?php -/* $Id: oo_rename.phpt,v 1.1.2.1.2.1 2008/05/21 09:27:41 pajoye Exp $ */ +/* $Id: oo_rename.phpt 260091 2008-05-21 09:27:41Z pajoye $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- diff --git a/ext/zip/tests/oo_setcomment.phpt b/ext/zip/tests/oo_setcomment.phpt index 872f6e6ff..9fb742d9a 100644 --- a/ext/zip/tests/oo_setcomment.phpt +++ b/ext/zip/tests/oo_setcomment.phpt @@ -2,7 +2,7 @@ setComment --SKIPIF-- <?php -/* $Id: oo_setcomment.phpt,v 1.1.2.2.2.1 2008/05/21 09:27:41 pajoye Exp $ */ +/* $Id: oo_setcomment.phpt 260091 2008-05-21 09:27:41Z pajoye $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- diff --git a/ext/zip/tests/oo_stream.phpt b/ext/zip/tests/oo_stream.phpt index 3d952b805..cddd5e8e7 100644 --- a/ext/zip/tests/oo_stream.phpt +++ b/ext/zip/tests/oo_stream.phpt @@ -2,7 +2,7 @@ getStream --SKIPIF-- <?php -/* $Id: oo_stream.phpt,v 1.2.2.2.2.1 2008/05/21 09:27:41 pajoye Exp $ */ +/* $Id: oo_stream.phpt 260091 2008-05-21 09:27:41Z pajoye $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- diff --git a/ext/zip/tests/utils.inc b/ext/zip/tests/utils.inc index c9ab36976..3b4cb6b9c 100644 --- a/ext/zip/tests/utils.inc +++ b/ext/zip/tests/utils.inc @@ -1,5 +1,5 @@ <?php -/* $Id: utils.inc,v 1.1.2.3.2.1 2008/05/21 09:27:41 pajoye Exp $ */ +/* $Id: utils.inc 260091 2008-05-21 09:27:41Z pajoye $ */ function dump_entries_name($z) { for($i=0; $i<$z->numFiles; $i++) { $sb = $z->statIndex($i); diff --git a/ext/zip/tests/zip_close.phpt b/ext/zip/tests/zip_close.phpt index 93753e4fe..e59bf3ed7 100644 --- a/ext/zip/tests/zip_close.phpt +++ b/ext/zip/tests/zip_close.phpt @@ -2,7 +2,7 @@ zip_close() function --SKIPIF-- <?php -/* $Id: zip_close.phpt,v 1.1.4.1 2008/05/21 09:27:41 pajoye Exp $ */ +/* $Id: zip_close.phpt 260091 2008-05-21 09:27:41Z pajoye $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- diff --git a/ext/zip/tests/zip_entry_compressedsize.phpt b/ext/zip/tests/zip_entry_compressedsize.phpt index ced546db4..29f305cc6 100644 --- a/ext/zip/tests/zip_entry_compressedsize.phpt +++ b/ext/zip/tests/zip_entry_compressedsize.phpt @@ -2,7 +2,7 @@ zip_entry_compressedsize() function --SKIPIF-- <?php -/* $Id: zip_entry_compressedsize.phpt,v 1.1.4.1 2008/05/21 09:27:41 pajoye Exp $ */ +/* $Id: zip_entry_compressedsize.phpt 260091 2008-05-21 09:27:41Z pajoye $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- diff --git a/ext/zip/tests/zip_entry_compressionmethod.phpt b/ext/zip/tests/zip_entry_compressionmethod.phpt index c52a3e7fe..1705d32c0 100644 --- a/ext/zip/tests/zip_entry_compressionmethod.phpt +++ b/ext/zip/tests/zip_entry_compressionmethod.phpt @@ -2,7 +2,7 @@ zip_entry_compressionmethod() function --SKIPIF-- <?php -/* $Id: zip_entry_compressionmethod.phpt,v 1.1.4.1 2008/05/21 09:27:41 pajoye Exp $ */ +/* $Id: zip_entry_compressionmethod.phpt 260091 2008-05-21 09:27:41Z pajoye $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- diff --git a/ext/zip/tests/zip_entry_filesize.phpt b/ext/zip/tests/zip_entry_filesize.phpt index 0d71f5f70..a10a0b22c 100644 --- a/ext/zip/tests/zip_entry_filesize.phpt +++ b/ext/zip/tests/zip_entry_filesize.phpt @@ -2,7 +2,7 @@ zip_entry_filesize() function --SKIPIF-- <?php -/* $Id: zip_entry_filesize.phpt,v 1.1.4.1 2008/05/21 09:27:41 pajoye Exp $ */ +/* $Id: zip_entry_filesize.phpt 260091 2008-05-21 09:27:41Z pajoye $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- diff --git a/ext/zip/tests/zip_entry_name.phpt b/ext/zip/tests/zip_entry_name.phpt index 178c4fb60..42bb07cf6 100644 --- a/ext/zip/tests/zip_entry_name.phpt +++ b/ext/zip/tests/zip_entry_name.phpt @@ -2,7 +2,7 @@ zip_entry_name() function --SKIPIF-- <?php -/* $Id: zip_entry_name.phpt,v 1.1.4.1 2008/05/21 09:27:41 pajoye Exp $ */ +/* $Id: zip_entry_name.phpt 260091 2008-05-21 09:27:41Z pajoye $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- diff --git a/ext/zip/tests/zip_entry_open.phpt b/ext/zip/tests/zip_entry_open.phpt index 1933025f4..c3dabe858 100644 --- a/ext/zip/tests/zip_entry_open.phpt +++ b/ext/zip/tests/zip_entry_open.phpt @@ -2,7 +2,7 @@ zip_entry_open() function --SKIPIF-- <?php -/* $Id: zip_entry_open.phpt,v 1.1.2.1.2.1 2008/05/21 09:27:41 pajoye Exp $ */ +/* $Id: zip_entry_open.phpt 260091 2008-05-21 09:27:41Z pajoye $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- diff --git a/ext/zip/tests/zip_entry_read.phpt b/ext/zip/tests/zip_entry_read.phpt index ba020e316..f2b502297 100644 --- a/ext/zip/tests/zip_entry_read.phpt +++ b/ext/zip/tests/zip_entry_read.phpt @@ -2,7 +2,7 @@ zip_entry_read() function --SKIPIF-- <?php -/* $Id: zip_entry_read.phpt,v 1.1.2.1.2.1 2008/05/21 09:27:41 pajoye Exp $ */ +/* $Id: zip_entry_read.phpt 260091 2008-05-21 09:27:41Z pajoye $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- diff --git a/ext/zip/tests/zip_open.phpt b/ext/zip/tests/zip_open.phpt index 4e038745b..e63c40e30 100644 --- a/ext/zip/tests/zip_open.phpt +++ b/ext/zip/tests/zip_open.phpt @@ -2,7 +2,7 @@ zip_open() function --SKIPIF-- <?php -/* $Id: zip_open.phpt,v 1.1.4.1 2008/05/21 09:27:41 pajoye Exp $ */ +/* $Id: zip_open.phpt 260091 2008-05-21 09:27:41Z pajoye $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- diff --git a/ext/zip/tests/zip_open_error.phpt b/ext/zip/tests/zip_open_error.phpt new file mode 100644 index 000000000..eaa1d9731 --- /dev/null +++ b/ext/zip/tests/zip_open_error.phpt @@ -0,0 +1,28 @@ +--TEST-- +zip_open() error conditions +--CREDITS-- +Birgitte Kvarme <bitta@redpill-linpro.com> +#PHPTestFest2009 Norway 2009-06-09 \o/ +--SKIPIF-- +<?php +if(!extension_loaded('zip')) die('skip'); +?> +--FILE-- +<?php +echo "Test case 1:"; +$zip = zip_open(""); + +echo "Test case 2:"; +$zip = zip_open("i_dont_care_about_this_parameter", "this_is_one_to_many"); + +echo "Test case 3:\n"; +$zip = zip_open("/non_exisitng_directory/test_procedural.zip"); +echo is_resource($zip) ? "OK" : "Failure"; +?> +--EXPECTF-- +Test case 1: +Warning: zip_open(): Empty string as source in %s on line %d +Test case 2: +Warning: zip_open() expects exactly 1 parameter, 2 given in %s on line %d +Test case 3: +Failure diff --git a/ext/zip/tests/zip_read.phpt b/ext/zip/tests/zip_read.phpt index f9b722654..654e22fa4 100644 --- a/ext/zip/tests/zip_read.phpt +++ b/ext/zip/tests/zip_read.phpt @@ -2,7 +2,7 @@ zip_read() function --SKIPIF-- <?php -/* $Id: zip_read.phpt,v 1.1.4.1 2008/05/21 09:27:41 pajoye Exp $ */ +/* $Id: zip_read.phpt 260091 2008-05-21 09:27:41Z pajoye $ */ if(!extension_loaded('zip')) die('skip'); ?> --FILE-- diff --git a/ext/zip/zip_stream.c b/ext/zip/zip_stream.c index 5acf4d57c..a3c37ffd0 100644 --- a/ext/zip/zip_stream.c +++ b/ext/zip/zip_stream.c @@ -1,4 +1,4 @@ -/* $Id: zip_stream.c,v 1.1.2.5.2.2 2008/07/23 11:25:14 tony2001 Exp $ */ +/* $Id: zip_stream.c 287101 2009-08-11 17:08:23Z pajoye $ */ #ifdef HAVE_CONFIG_H # include "config.h" #endif @@ -35,14 +35,20 @@ static size_t php_zip_ops_read(php_stream *stream, char *buf, size_t count TSRML if (self->za && self->zf) { n = (size_t)zip_fread(self->zf, buf, (int)count); - - if (n == 0) { + if (n < 0) { + int ze, se; + zip_file_error_get(self->zf, &ze, &se); + stream->eof = 1; + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Zip stream error: %s", zip_file_strerror(self->zf)); + return 0; + } + if (n == 0 || n < count) { stream->eof = 1; } else { self->cursor += n; } } - return n<1 ? 0 : n; + return (n < 1 ? 0 : n); } /* }}} */ @@ -62,14 +68,15 @@ static int php_zip_ops_close(php_stream *stream, int close_handle TSRMLS_DC) { STREAM_DATA_FROM_STREAM(); if (close_handle) { - if (self->za) { - zip_close(self->za); - self->za = NULL; - } if (self->zf) { zip_fclose(self->zf); self->zf = NULL; } + + if (self->za) { + zip_close(self->za); + self->za = NULL; + } } efree(self); stream->abstract = NULL; |
