diff options
| author | Greg Beaver <cellog@php.net> | 2008-05-29 17:34:50 +0000 |
|---|---|---|
| committer | Greg Beaver <cellog@php.net> | 2008-05-29 17:34:50 +0000 |
| commit | 4cc79b39b45bea32a0e6de04361593f0d5a91ebc (patch) | |
| tree | a372c39db18d3717a1edf0fb8b4e16fc773960f3 | |
| parent | e49404929abd9fe03eee5489970b7fb0458bc2b5 (diff) | |
| download | php-git-4cc79b39b45bea32a0e6de04361593f0d5a91ebc.tar.gz | |
fix PECL bug #13981: Third-party zips fail entry interrogation
| -rw-r--r-- | ext/phar/phar.c | 11 | ||||
| -rw-r--r-- | ext/phar/tests/zip/unixzip.phpt | 15 |
2 files changed, 15 insertions, 11 deletions
diff --git a/ext/phar/phar.c b/ext/phar/phar.c index 5a203b5347..f38188e957 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -1980,15 +1980,16 @@ int phar_postprocess_file(php_stream_wrapper *wrapper, int options, phar_entry_d spprintf(error, 0, "phar error: internal corruption of zip-based phar \"%s\" (cannot read local file header for file \"%s\")", idata->phar->fname, entry->filename); return FAILURE; } - /* fix up for big-endian systems */ - /* verify local header if not yet verified */ + /* verify local header */ if (entry->filename_len != PHAR_ZIP_16(local.filename_len) || entry->crc32 != PHAR_ZIP_32(local.crc32) || entry->uncompressed_filesize != PHAR_ZIP_32(local.uncompsize) || entry->compressed_filesize != PHAR_ZIP_32(local.compsize)) { spprintf(error, 0, "phar error: internal corruption of zip-based phar \"%s\" (local head of file \"%s\" does not match central directory)", idata->phar->fname, entry->filename); return FAILURE; } - if (-1 == php_stream_seek(idata->phar->fp, PHAR_ZIP_16(local.filename_len) + PHAR_ZIP_16(local.extra_len), SEEK_CUR)) { - spprintf(error, 0, "phar error: internal corruption of zip-based phar \"%s\" (cannot seek to start of file data for file \"%s\")", idata->phar->fname, entry->filename); - return FAILURE; + /* construct actual offset to file start - local extra_len can be different from central extra_len */ + entry->offset = entry->offset_abs = + sizeof(local) + entry->header_offset + PHAR_ZIP_16(local.filename_len) + PHAR_ZIP_16(local.extra_len); + if (idata->zero != entry->offset_abs) { + idata->zero = entry->offset_abs; } } php_stream_seek(fp, idata->zero, SEEK_SET); diff --git a/ext/phar/tests/zip/unixzip.phpt b/ext/phar/tests/zip/unixzip.phpt index 374489d013..8eda6e025d 100644 --- a/ext/phar/tests/zip/unixzip.phpt +++ b/ext/phar/tests/zip/unixzip.phpt @@ -10,7 +10,8 @@ foreach ($a as $b) { if ($b->isDir()) { echo "dir " . $b->getPathName() . "\n"; } else { - echo $b->getPathName() . "\n"; + echo $b->getPathName(), "\n"; + echo file_get_contents($b->getPathName()), "\n"; } } if (isset($a['notempty/hi.txt'])) { @@ -19,8 +20,10 @@ if (isset($a['notempty/hi.txt'])) { ?> ===DONE=== --EXPECTF-- -dir phar://%szip.zip%cempty -phar://%szip.zip%chi.txt -dir phar://%szip.zip%cnotempty -phar://%szip.zip/notempty/hi.txt -===DONE=== +dir phar:///home/cellog/workspace/php5/ext/phar/tests/zip/files/zip.zip/empty +phar:///home/cellog/workspace/php5/ext/phar/tests/zip/files/zip.zip/hi.txt +hi there + +dir phar:///home/cellog/workspace/php5/ext/phar/tests/zip/files/zip.zip/notempty +phar:///home/cellog/workspace/php5/ext/phar/tests/zip/files/zip.zip/notempty/hi.txt +===DONE===
\ No newline at end of file |
