summaryrefslogtreecommitdiff
path: root/ext/zip/php_zip.c
diff options
context:
space:
mode:
authorPierre Joye <pajoye@php.net>2006-08-13 00:52:59 +0000
committerPierre Joye <pajoye@php.net>2006-08-13 00:52:59 +0000
commit9d26a88c3d36330d85a418b481135acb56501134 (patch)
tree5f951905182338b871db4e82aa1bb18c7729ffe3 /ext/zip/php_zip.c
parenta16935fd422272436f1cddd466d6c1c0175625f4 (diff)
downloadphp-git-9d26a88c3d36330d85a418b481135acb56501134.tar.gz
- temp fix for a segfault happening when one adds two entries with
the same name
Diffstat (limited to 'ext/zip/php_zip.c')
-rw-r--r--ext/zip/php_zip.c37
1 files changed, 36 insertions, 1 deletions
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;
}
}
/* }}} */