From: Pierre Joye Date: Fri, 15 Sep 2006 12:10:50 +0000 (+0000) Subject: - PECL Bug #8700, zipArchive::getFromIndex() fails X-Git-Tag: RELEASE_1_0_0RC1~1665 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a072c661842311798d03568df4e9e422b75c8586;p=php - PECL Bug #8700, zipArchive::getFromIndex() fails --- diff --git a/ext/zip/php_zip.c b/ext/zip/php_zip.c index 3e13334552..1caa6cdaa6 100644 --- a/ext/zip/php_zip.c +++ b/ext/zip/php_zip.c @@ -1719,7 +1719,7 @@ static void php_zip_get_from(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */ char *filename; int filename_len; - long index; + long index = -1; long flags = 0; long len = 0; @@ -1753,8 +1753,12 @@ static void php_zip_get_from(INTERNAL_FUNCTION_PARAMETERS, int type) /* {{{ */ if (len < 1) { len = sb.size; } + if (index >= 0) { + zf = zip_fopen_index(intern, index, flags); + } else { + zf = zip_fopen(intern, filename, flags); + } - zf = zip_fopen(intern, filename, flags); if (zf == NULL) { RETURN_FALSE; } diff --git a/ext/zip/tests/bug8700.phpt b/ext/zip/tests/bug8700.phpt new file mode 100644 index 0000000000..5e7df4560b --- /dev/null +++ b/ext/zip/tests/bug8700.phpt @@ -0,0 +1,30 @@ +--TEST-- +bug #8700, getFromIndex(0) fails +--SKIPIF-- + +--FILE-- +open($filename) === FALSE) { + exit("cannot open $filename\n"); +} +$contents_from_idx = $zip->getFromIndex(0); +$contents_from_name = $zip->getFromName('1.txt'); +if ($contents_from_idx != $contents_from_name) { + echo "failed:"; + var_dump($content_from_idx, $content_from_name); +} + +$zip->close(); +echo "status: " . $zip->status . "\n"; +echo "\n"; + +--EXPECT-- +status: 0