Modified: pecl/phar/trunk/package.php =================================================================== --- pecl/phar/trunk/package.php 2009-07-23 16:40:47 UTC (rev 284659) +++ pecl/phar/trunk/package.php 2009-07-23 17:04:24 UTC (rev 284660) @@ -52,6 +52,7 @@ fixed PHP Bug #48783: make install will fail saying phar file exists fixed PHP Bug #48740: PHAR install fails when INSTALL_ROOT is not the final install location fixed PHP Bug #48681: openssl signature verification for tar archives broken + fixed PHP Bug #48377: error message unclear on converting phar with existing file fixed isset() on sub-directories (isset("blah") if file "blah/foo.php" exists) Changes since 2.0.0RC1: security vulnerability in handling of long tar filenames fixed Modified: pecl/phar/trunk/phar_object.c =================================================================== --- pecl/phar/trunk/phar_object.c 2009-07-23 16:40:47 UTC (rev 284659) +++ pecl/phar/trunk/phar_object.c 2009-07-23 17:04:24 UTC (rev 284660) @@ -2043,6 +2043,7 @@ int ext_len = ext ? strlen(ext) : 0; int oldname_len; phar_archive_data **pphar = NULL; + php_stream_statbuf ssb; if (!ext) { if (phar->is_zip) { @@ -2113,6 +2114,8 @@ spprintf(&newname, 0, "%s.%s", strtok(basename, "."), ext); efree(basename); + + basepath = estrndup(oldpath, (strlen(oldpath) - oldname_len)); phar->fname_len = spprintf(&newpath, 0, "%s%s", basepath, newname); phar->fname = newpath; @@ -2148,6 +2151,11 @@ return NULL; } its_ok: + if (SUCCESS == php_stream_stat_path(newpath, &ssb)) { + efree(oldpath); + zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "phar \"%s\" exists and must be unlinked prior to conversion", newpath); + return NULL; + } if (!phar->is_data) { if (SUCCESS != phar_detect_phar_fname_ext(newpath, phar->fname_len, (const char **) &(phar->ext), &(phar->ext_len), 1, 1, 1 TSRMLS_CC)) { efree(oldpath); Added: pecl/phar/trunk/tests/bug48377.2.phpt =================================================================== --- pecl/phar/trunk/tests/bug48377.2.phpt (rev 0) +++ pecl/phar/trunk/tests/bug48377.2.phpt 2009-07-23 17:04:24 UTC (rev 284660) @@ -0,0 +1,25 @@ +--TEST-- +Phar: PHP bug #48377 "error message unclear on converting phar with existing file" test #2 +--SKIPIF-- + +--INI-- +phar.require_hash=0 +phar.readonly=0 +--FILE-- +convertToData(Phar::ZIP, Phar::NONE, '.2.phar.zip'); +} catch (BadMethodCallException $e) { + echo $e->getMessage(),"\n"; +} +?> +===DONE=== +--CLEAN-- + +--EXPECTF-- +data phar "%sbug48377.2.phar.zip" has invalid extension 2.phar.zip +===DONE=== \ No newline at end of file Added: pecl/phar/trunk/tests/bug48377.phpt =================================================================== --- pecl/phar/trunk/tests/bug48377.phpt (rev 0) +++ pecl/phar/trunk/tests/bug48377.phpt 2009-07-23 17:04:24 UTC (rev 284660) @@ -0,0 +1,29 @@ +--TEST-- +Phar: PHP bug #48377 "error message unclear on converting phar with existing file" +--SKIPIF-- + +--INI-- +phar.require_hash=0 +phar.readonly=0 +--FILE-- +convertToData(Phar::ZIP, Phar::NONE, 'zip'); +} catch (BadMethodCallException $e) { + echo $e->getMessage(),"\n"; +} +?> +===DONE=== +--CLEAN-- + + +--EXPECTF-- +phar "%sbug48377.zip" exists and must be unlinked prior to conversion +===DONE=== \ No newline at end of file Modified: php/php-src/branches/PHP_5_3/NEWS =================================================================== --- php/php-src/branches/PHP_5_3/NEWS 2009-07-23 16:40:47 UTC (rev 284659) +++ php/php-src/branches/PHP_5_3/NEWS 2009-07-23 17:04:24 UTC (rev 284660) @@ -43,6 +43,8 @@ components). (Ilia) - Fixed bug #48681 (openssl signature verification for tar archives broken). (Greg) +- Fixed bug #48377 (error message unclear on converting phar with existing file). + (Greg) - Fixed bug #48247 (Infinite loop and possible crash during startup with errors when errors are logged). (Jani) - Fixed bug #48116 (Fixed build with Openssl 1.0). (Pierre, Modified: php/php-src/branches/PHP_5_3/ext/phar/phar_object.c =================================================================== --- php/php-src/branches/PHP_5_3/ext/phar/phar_object.c 2009-07-23 16:40:47 UTC (rev 284659) +++ php/php-src/branches/PHP_5_3/ext/phar/phar_object.c 2009-07-23 17:04:24 UTC (rev 284660) @@ -2037,6 +2037,7 @@ int ext_len = ext ? strlen(ext) : 0; int oldname_len; phar_archive_data **pphar = NULL; + php_stream_statbuf ssb; if (!ext) { if (phar->is_zip) { @@ -2107,6 +2108,8 @@ spprintf(&newname, 0, "%s.%s", strtok(basename, "."), ext); efree(basename); + + basepath = estrndup(oldpath, (strlen(oldpath) - oldname_len)); phar->fname_len = spprintf(&newpath, 0, "%s%s", basepath, newname); phar->fname = newpath; @@ -2142,6 +2145,11 @@ return NULL; } its_ok: + if (SUCCESS == php_stream_stat_path(newpath, &ssb)) { + efree(oldpath); + zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "phar \"%s\" exists and must be unlinked prior to conversion", newpath); + return NULL; + } if (!phar->is_data) { if (SUCCESS != phar_detect_phar_fname_ext(newpath, phar->fname_len, (const char **) &(phar->ext), &(phar->ext_len), 1, 1, 1 TSRMLS_CC)) { efree(oldpath); Added: php/php-src/branches/PHP_5_3/ext/phar/tests/bug48377.2.phpt =================================================================== --- php/php-src/branches/PHP_5_3/ext/phar/tests/bug48377.2.phpt (rev 0) +++ php/php-src/branches/PHP_5_3/ext/phar/tests/bug48377.2.phpt 2009-07-23 17:04:24 UTC (rev 284660) @@ -0,0 +1,25 @@ +--TEST-- +Phar: PHP bug #48377 "error message unclear on converting phar with existing file" test #2 +--SKIPIF-- + +--INI-- +phar.require_hash=0 +phar.readonly=0 +--FILE-- +convertToData(Phar::ZIP, Phar::NONE, '.2.phar.zip'); +} catch (BadMethodCallException $e) { + echo $e->getMessage(),"\n"; +} +?> +===DONE=== +--CLEAN-- + +--EXPECTF-- +data phar "%sbug48377.2.phar.zip" has invalid extension 2.phar.zip +===DONE=== \ No newline at end of file Added: php/php-src/branches/PHP_5_3/ext/phar/tests/bug48377.phpt =================================================================== --- php/php-src/branches/PHP_5_3/ext/phar/tests/bug48377.phpt (rev 0) +++ php/php-src/branches/PHP_5_3/ext/phar/tests/bug48377.phpt 2009-07-23 17:04:24 UTC (rev 284660) @@ -0,0 +1,29 @@ +--TEST-- +Phar: PHP bug #48377 "error message unclear on converting phar with existing file" +--SKIPIF-- + +--INI-- +phar.require_hash=0 +phar.readonly=0 +--FILE-- +convertToData(Phar::ZIP, Phar::NONE, 'zip'); +} catch (BadMethodCallException $e) { + echo $e->getMessage(),"\n"; +} +?> +===DONE=== +--CLEAN-- + + +--EXPECTF-- +phar "%sbug48377.zip" exists and must be unlinked prior to conversion +===DONE=== \ No newline at end of file Modified: php/php-src/trunk/ext/phar/phar_object.c =================================================================== --- php/php-src/trunk/ext/phar/phar_object.c 2009-07-23 16:40:47 UTC (rev 284659) +++ php/php-src/trunk/ext/phar/phar_object.c 2009-07-23 17:04:24 UTC (rev 284660) @@ -2037,6 +2037,7 @@ int ext_len = ext ? strlen(ext) : 0; int oldname_len; phar_archive_data **pphar = NULL; + php_stream_statbuf ssb; if (!ext) { if (phar->is_zip) { @@ -2107,6 +2108,8 @@ spprintf(&newname, 0, "%s.%s", strtok(basename, "."), ext); efree(basename); + + basepath = estrndup(oldpath, (strlen(oldpath) - oldname_len)); phar->fname_len = spprintf(&newpath, 0, "%s%s", basepath, newname); phar->fname = newpath; @@ -2142,6 +2145,11 @@ return NULL; } its_ok: + if (SUCCESS == php_stream_stat_path(newpath, &ssb)) { + efree(oldpath); + zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "phar \"%s\" exists and must be unlinked prior to conversion", newpath); + return NULL; + } if (!phar->is_data) { if (SUCCESS != phar_detect_phar_fname_ext(newpath, phar->fname_len, (const char **) &(phar->ext), &(phar->ext_len), 1, 1, 1 TSRMLS_CC)) { efree(oldpath); Added: php/php-src/trunk/ext/phar/tests/bug48377.2.phpt =================================================================== --- php/php-src/trunk/ext/phar/tests/bug48377.2.phpt (rev 0) +++ php/php-src/trunk/ext/phar/tests/bug48377.2.phpt 2009-07-23 17:04:24 UTC (rev 284660) @@ -0,0 +1,25 @@ +--TEST-- +Phar: PHP bug #48377 "error message unclear on converting phar with existing file" test #2 +--SKIPIF-- + +--INI-- +phar.require_hash=0 +phar.readonly=0 +--FILE-- +convertToData(Phar::ZIP, Phar::NONE, '.2.phar.zip'); +} catch (BadMethodCallException $e) { + echo $e->getMessage(),"\n"; +} +?> +===DONE=== +--CLEAN-- + +--EXPECTF-- +data phar "%sbug48377.2.phar.zip" has invalid extension 2.phar.zip +===DONE=== \ No newline at end of file Added: php/php-src/trunk/ext/phar/tests/bug48377.phpt =================================================================== --- php/php-src/trunk/ext/phar/tests/bug48377.phpt (rev 0) +++ php/php-src/trunk/ext/phar/tests/bug48377.phpt 2009-07-23 17:04:24 UTC (rev 284660) @@ -0,0 +1,29 @@ +--TEST-- +Phar: PHP bug #48377 "error message unclear on converting phar with existing file" +--SKIPIF-- + +--INI-- +phar.require_hash=0 +phar.readonly=0 +--FILE-- +convertToData(Phar::ZIP, Phar::NONE, 'zip'); +} catch (BadMethodCallException $e) { + echo $e->getMessage(),"\n"; +} +?> +===DONE=== +--CLEAN-- + + +--EXPECTF-- +phar "%sbug48377.zip" exists and must be unlinked prior to conversion +===DONE=== \ No newline at end of file