]> granicus.if.org Git - php/commitdiff
- Fixed bug #53893 (Wrong return value for ZipArchive::extractTo())
authorPierre Joye <pajoye@php.net>
Mon, 7 Feb 2011 16:20:16 +0000 (16:20 +0000)
committerPierre Joye <pajoye@php.net>
Mon, 7 Feb 2011 16:20:16 +0000 (16:20 +0000)
ext/zip/php_zip.c
ext/zip/tests/bug53603.phpt

index e5ffc874a1a38d7bcb792a4a5c8c9f3696046fb9..c51d2f6aebce40c750610da541e3d59ebfabac82 100644 (file)
@@ -235,6 +235,10 @@ static int php_zip_extract_file(struct zip * za, char *dest, char *file, int fil
                return 0;
        } else if (len > MAXPATHLEN) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Full extraction path exceed MAXPATHLEN (%i)", MAXPATHLEN);
+               efree(file_dirname_fullpath);
+               efree(file_basename);
+               free(new_state.cwd);
+               return 0;
        }
 
        /* check again the full path, not sure if it
@@ -249,27 +253,42 @@ static int php_zip_extract_file(struct zip * za, char *dest, char *file, int fil
                return 0;
        }
 
+#if PHP_API_VERSION < 20100412
+       stream = php_stream_open_wrapper(fullpath, "w+b", REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL);
+#else
+       stream = php_stream_open_wrapper(fullpath, "w+b", REPORT_ERRORS, NULL);
+#endif
+
+       if (stream == NULL) {
+               n = -1;
+               goto done;
+       }
+
        zf = zip_fopen(za, file, 0);
        if (zf == NULL) {
+               n = -1;
+               php_stream_close(stream);
+               goto done;
+       }
+
+       n = 0;
+       if (stream == NULL) {
+               int ret = zip_fclose(zf);
                efree(fullpath);
-               efree(file_dirname_fullpath);
                efree(file_basename);
+               efree(file_dirname_fullpath);
                free(new_state.cwd);
                return 0;
        }
 
-#if PHP_API_VERSION < 20100412
-       stream = php_stream_open_wrapper(fullpath, "w+b", REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL);
-#else
-       stream = php_stream_open_wrapper(fullpath, "w+b", REPORT_ERRORS, NULL);
-#endif
-       n = 0;
-       if (stream) {
-               while ((n=zip_fread(zf, b, sizeof(b))) > 0) php_stream_write(stream, b, n);
-               php_stream_close(stream);
+       while ((n=zip_fread(zf, b, sizeof(b))) > 0) {
+               php_stream_write(stream, b, n);
        }
+
+       php_stream_close(stream);
        n = zip_fclose(zf);
 
+done:
        efree(fullpath);
        efree(file_basename);
        efree(file_dirname_fullpath);
index 7be20dc0e3092c043bd5f25629f4899e7b8b765a..f8ff1b4d4402431121e75e32ce66dcbec43d64ad 100644 (file)
@@ -29,10 +29,7 @@ $a = $zip->extractTo('teststream://test');
 var_dump($a);
 
 --EXPECTF--
-Warning: ZipArchive::extractTo(teststream://test/foo): failed to open stream: "TestStream::stream_open" call failed in %s on line %d
-
-Warning: ZipArchive::extractTo(teststream://test/bar): failed to open stream: "TestStream::stream_open" call failed in %s on line %d
 
-Warning: ZipArchive::extractTo(teststream://test/foobar/baz): failed to open stream: "TestStream::stream_open" call failed in %s on line %d
-bool(true)
+Warning: ZipArchive::extractTo(teststream://test/foo): failed to open stream: "TestStream::stream_open" call failed in %s on line %d
+bool(false)