Patch Added_encryption_for_ZipArchive_module for Zip Related Bug #62898
Patch version 2012-08-22 18:45 UTC
Return to Bug #62898 |
Download this patch
Patch Revisions:
Developer: l117158@rtrtr.com
From ae59bf69d6ebf67777a206ae14ceab6591988262 Mon Sep 17 00:00:00 2001
Date: Wed, 22 Aug 2012 21:33:36 +0400
Subject: [PATCH] Added encryption for ZipArchive module
---
ext/zip/php_zip.c | 15 ++++++++---
ext/zip/tests/oo_zip_entry_encrypted_read.phpt | 35 +++++++++++++++++++++++++
ext/zip/tests/test_password-protected.zip | Bin 0 -> 232 bytes
3 files changed, 46 insertions(+), 4 deletions(-)
create mode 100644 ext/zip/tests/oo_zip_entry_encrypted_read.phpt
create mode 100644 ext/zip/tests/test_password-protected.zip
diff --git a/ext/zip/php_zip.c b/ext/zip/php_zip.c
index 74f868b..4801699 100644
--- a/ext/zip/php_zip.c
+++ b/ext/zip/php_zip.c
@@ -1477,13 +1477,13 @@ static PHP_NAMED_FUNCTION(zif_zip_entry_compressionmethod)
/* }}} */
#ifdef PHP_ZIP_USE_OO
-/* {{{ proto mixed ZipArchive::open(string source [, int flags])
+/* {{{ proto mixed ZipArchive::open(string source [, int flags, string password])
Create new zip using source uri for output, return TRUE on success or the error code */
static ZIPARCHIVE_METHOD(open)
{
struct zip *intern;
- char *filename;
- int filename_len;
+ char *filename,*pass;
+ int filename_len,pass_len;
int err = 0;
long flags = 0;
char resolved_path[MAXPATHLEN];
@@ -1491,7 +1491,7 @@ static ZIPARCHIVE_METHOD(open)
zval *this = getThis();
ze_zip_object *ze_obj = NULL;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|l", &filename, &filename_len, &flags) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "p|ls!", &filename, &filename_len, &flags,&pass, &pass_len) == FAILURE) {
return;
}
@@ -1526,9 +1526,16 @@ static ZIPARCHIVE_METHOD(open)
}
intern = zip_open(resolved_path, flags, &err);
+
if (!intern || err) {
RETURN_LONG((long)err);
}
+
+ err=zip_set_default_password(intern,(const char *)pass);
+ if(err){
+ RETURN_LONG((long)err);
+ }
+
ze_obj->filename = estrdup(resolved_path);
ze_obj->filename_len = filename_len;
ze_obj->za = intern;
diff --git a/ext/zip/tests/oo_zip_entry_encrypted_read.phpt b/ext/zip/tests/oo_zip_entry_encrypted_read.phpt
new file mode 100644
index 0000000..3e6d719
--- /dev/null
+++ b/ext/zip/tests/oo_zip_entry_encrypted_read.phpt
@@ -0,0 +1,35 @@
+--TEST--
+zip::open() function with encryption
+--SKIPIF--
+<?php
+/* $Id$ */
+if(!extension_loaded('zip')) die('skip');
+?>
+--FILE--
+<?php
+$zip = new ZipArchive;
+$zip->open('');
+
+if (!$zip->open($dirname . 'test_password-protected.zip',ZIPARCHIVE::EXCL,'test')) {
+ exit("failed 1\n");
+}
+if ($zip->status == ZIPARCHIVE::ER_OK) {
+ echo "open OK\n";
+} else {
+ echo "failed\n";
+}
+$fp=$zip->getStream('test_password-protected.txt');
+if(!$fp)
+ echo "open file OK\n";
+} else {
+ echo "failed\n";
+}
+echo stream_get_contents($fp);
+fclose($fp);
+
+
+?>
+--EXPECTF--
+open OK
+open file OK
+test_protected
diff --git a/ext/zip/tests/test_password-protected.zip b/ext/zip/tests/test_password-protected.zip
new file mode 100644
index 0000000000000000000000000000000000000000..fd6a8b1607854521279a3904d71191d87267e412
GIT binary patch
literal 232
zcmWIWW@Zs#;AG%nU|A{VSn>byI~fKB20kE`2I7*`;*$7+#Ny)e{Gt@yf};GA)Z~)X
z6upv)k}|cEkxMjwE^g?1apraB;-yWB4z~Lk<zzHBA7u#eX6HaQD!`kONuB|hH7Y=h
xKtKUZ;<c0us)&(6f+01gY)ePOSw?#^2rc|2AIuN%W@Q7J#0Z4BKsps{ECA>xKdS%$
literal 0
HcmV?d00001
--
1.7.11.msysgit.1
|