From 56650fa4cde31d114ccb0830ffa33e026a4863f3 Mon Sep 17 00:00:00 2001 From: Greg Beaver Date: Sun, 20 Apr 2008 05:41:41 +0000 Subject: [PATCH] amend zip test to actually test file perms creation/reading and fix severely broken permissions creation --- ext/phar/tests/zip/033.phpt | 8 ++++++-- ext/phar/zip.c | 32 +++++++++++++++++--------------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/ext/phar/tests/zip/033.phpt b/ext/phar/tests/zip/033.phpt index 6cb2e8afd2..3c1e2de7bc 100644 --- a/ext/phar/tests/zip/033.phpt +++ b/ext/phar/tests/zip/033.phpt @@ -9,6 +9,7 @@ phar.require_hash=0 stopBuffering(); try { var_dump($phar['a.php']->isExecutable()); $phar['a.php']->chmod(0777); - var_dump($phar['a.php']->isExecutable()); + copy($fname, $fname2); + $phar2 = new Phar($fname2); + var_dump($phar2['a.php']->isExecutable()); $phar['a.php']->chmod(0666); var_dump($phar['a.php']->isExecutable()); echo "test dir\n"; @@ -36,8 +39,9 @@ try { ?> ===DONE=== --CLEAN-- - --EXPECT-- bool(false) diff --git a/ext/phar/zip.c b/ext/phar/zip.c index 460321f0c1..cd35b874fa 100644 --- a/ext/phar/zip.c +++ b/ext/phar/zip.c @@ -40,32 +40,34 @@ static int phar_zip_process_extra(php_stream *fp, phar_entry_info *entry, php_ui phar_zip_extra_field_header header; phar_zip_unix3 unix3; } h; + int read; do { if (sizeof(h.header) != php_stream_read(fp, (char *) &h.header, sizeof(h.header))) { return FAILURE; } - /* clean up header for big-endian systems */ - if (h.header.tag[0] != 'u' || h.header.tag[1] != 'n') { + if (h.header.tag[0] != 'n' || h.header.tag[1] != 'u') { /* skip to next header */ php_stream_seek(fp, PHAR_GET_16(h.header.size), SEEK_CUR); len -= PHAR_GET_16(h.header.size) + 4; continue; } /* unix3 header found */ - /* clean up header for big-endian systems */ - if (sizeof(h.unix3) != php_stream_read(fp, (char *) &h.unix3, sizeof(h.unix3))) { - if (PHAR_GET_16(h.unix3.size) > sizeof(h.unix3) - 4) { - /* skip symlink filename - we may add this support in later */ - php_stream_seek(fp, h.unix3.size - sizeof(h.unix3.size), SEEK_CUR); - } - /* set permissions */ - entry->flags &= PHAR_ENT_COMPRESSION_MASK; - if (entry->is_dir) { - entry->flags |= PHAR_GET_16(h.unix3.perms) & PHAR_ENT_PERM_DEF_DIR; - } else { - entry->flags |= PHAR_GET_16(h.unix3.perms) & PHAR_ENT_PERM_DEF_FILE; - } + read = php_stream_read(fp, (char *) &(h.unix3.crc32), sizeof(h.unix3) - sizeof(h.header)); + len -= read + 4; + if (sizeof(h.unix3) - sizeof(h.header) != read) { + return FAILURE; + } + if (PHAR_GET_16(h.unix3.size) > sizeof(h.unix3) - 4) { + /* skip symlink filename - we may add this support in later */ + php_stream_seek(fp, h.unix3.size - sizeof(h.unix3.size), SEEK_CUR); + } + /* set permissions */ + entry->flags &= PHAR_ENT_COMPRESSION_MASK; + if (entry->is_dir) { + entry->flags |= PHAR_GET_16(h.unix3.perms) & PHAR_ENT_PERM_MASK; + } else { + entry->flags |= PHAR_GET_16(h.unix3.perms) & PHAR_ENT_PERM_MASK; } } while (len); return SUCCESS; -- 2.50.1