From: Pierre Joye Date: Sun, 13 Aug 2006 00:52:59 +0000 (+0000) Subject: - temp fix for a segfault happening when one adds two entries with X-Git-Tag: php-5.2.0RC2~44 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9d26a88c3d36330d85a418b481135acb56501134;p=php - temp fix for a segfault happening when one adds two entries with the same name --- diff --git a/ext/zip/TODO b/ext/zip/TODO index c1baba97ed..cb540ce7af 100644 --- a/ext/zip/TODO +++ b/ext/zip/TODO @@ -1,3 +1,4 @@ +- fix _zip_replace (add two entries with the same name segfaults) - add pattern support to extract or add files - stream to add or modify entries - crypt support for zip (read and write) diff --git a/ext/zip/php_zip.c b/ext/zip/php_zip.c index 96b8e4d578..d405ffd44f 100644 --- a/ext/zip/php_zip.c +++ b/ext/zip/php_zip.c @@ -956,6 +956,7 @@ ZIPARCHIVE_METHOD(addFile) int entry_name_len = 0; struct zip_source *zs; long offset_start = 0, offset_len = 0; + int cur_idx; if (!this) { RETURN_FALSE; @@ -987,7 +988,23 @@ ZIPARCHIVE_METHOD(addFile) if (!zs) { RETURN_FALSE; } - if (zip_add(intern, entry_name, zs) < 0) { + + cur_idx = zip_name_locate(intern, (const char *)entry_name, 0); + /* TODO: fix _zip_replace */ + if (cur_idx<0) { + /* reset the error */ + if (intern->error.str) { + _zip_error_fini(&intern->error); + } + _zip_error_init(&intern->error); + + } else { + if (zip_delete(intern, cur_idx) == -1) { + RETURN_FALSE; + } + } + + if (zip_add(intern, entry_name, zs) == -1) { RETURN_FALSE; } else { RETURN_TRUE; @@ -1006,6 +1023,7 @@ ZIPARCHIVE_METHOD(addFromString) ze_zip_object *ze_obj; struct zip_source *zs; int pos = 0; + int cur_idx; if (!this) { RETURN_FALSE; @@ -1037,8 +1055,25 @@ ZIPARCHIVE_METHOD(addFromString) RETURN_FALSE; } + cur_idx = zip_name_locate(intern, (const char *)name, 0); + /* TODO: fix _zip_replace */ + if (cur_idx<0) { + /* reset the error */ + if (intern->error.str) { + _zip_error_fini(&intern->error); + } + _zip_error_init(&intern->error); + + } else { + if (zip_delete(intern, cur_idx) == -1) { + RETURN_FALSE; + } + } + if (zip_add(intern, name, zs) == -1) { RETURN_FALSE; + } else { + RETURN_TRUE; } } /* }}} */