1 https://bugzilla.redhat.com/show_bug.cgi?id=551513
2 https://bugs.php.net/bug.php?id=39388
3 http://spot.fedorapeople.org/php-5.3.6-libzip.patch
4 pld fixes: link with -lzip when using system lib, -lz otherwise
6 diff -up php-5.4.5RC1/ext/zip/config.m4.systzip php-5.4.5RC1/ext/zip/config.m4
7 --- php-5.4.5RC1/ext/zip/config.m4.systzip 2012-07-04 07:43:14.000000000 +0200
8 +++ php-5.4.5RC1/ext/zip/config.m4 2012-07-07 15:56:41.418171233 +0200
9 @@ -13,65 +13,105 @@ fi
10 PHP_ARG_WITH(pcre-dir, pcre install prefix,
11 [ --with-pcre-dir ZIP: pcre install prefix], no, no)
13 -if test "$PHP_ZIP" != "no"; then
14 +PHP_ARG_WITH(libzip, libzip,
15 +[ --with-libzip[=DIR] ZIP: use libzip], no, no)
17 - if test "$PHP_ZLIB_DIR" != "no" && test "$PHP_ZLIB_DIR" != "yes"; then
18 - if test -f "$PHP_ZLIB_DIR/include/zlib/zlib.h"; then
19 - PHP_ZLIB_DIR="$PHP_ZLIB_DIR"
20 - PHP_ZLIB_INCDIR="$PHP_ZLIB_DIR/include/zlib"
21 - elif test -f "$PHP_ZLIB_DIR/include/zlib.h"; then
22 - PHP_ZLIB_DIR="$PHP_ZLIB_DIR"
23 - PHP_ZLIB_INCDIR="$PHP_ZLIB_DIR/include"
24 +if test "$PHP_ZIP" != "no"; then
25 + if test "$PHP_LIBZIP" != "no"; then
26 + dnl system libzip, depends on libzip
27 + if test -r $PHP_LIBZIP/include/zip.h; then
28 + LIBZIP_DIR=$PHP_LIBZIP
30 - AC_MSG_ERROR([Can not find zlib headers under "$PHP_ZLIB_DIR"])
31 + AC_MSG_CHECKING(for libzip in default path)
32 + for i in /usr/local /usr; do
33 + if test -r $i/include/zip.h; then
35 + AC_MSG_RESULT(found in $i)
41 + if test -z "$LIBZIP_DIR"; then
42 + AC_MSG_RESULT(not found)
43 + AC_MSG_ERROR(Please reinstall the libzip distribution)
46 + dnl Could not think of a simple way to check libzip for overwrite support
47 + PHP_CHECK_LIBRARY(zip, zip_open,
49 + PHP_ADD_INCLUDE($LIBZIP_DIR/include)
50 + PHP_ADD_LIBRARY_WITH_PATH(zip, $LIBZIP_DIR/$PHP_LIBDIR, ZIP_SHARED_LIBADD)
51 + AC_DEFINE(HAVE_LIBZIP,1,[ ])
53 + AC_MSG_ERROR(could not find usable libzip)
55 + -L$LIBZIP_DIR/$PHP_LIBDIR
58 + AC_DEFINE(HAVE_ZIP,1,[ ])
59 + PHP_NEW_EXTENSION(zip, php_zip.c zip_stream.c, $ext_shared)
60 + PHP_SUBST(ZIP_SHARED_LIBADD)
62 - for i in /usr/local /usr; do
63 - if test -f "$i/include/zlib/zlib.h"; then
65 - PHP_ZLIB_INCDIR="$i/include/zlib"
66 - elif test -f "$i/include/zlib.h"; then
68 - PHP_ZLIB_INCDIR="$i/include"
70 + dnl bundled libzip, depends on zlib
71 + if test "$PHP_ZLIB_DIR" != "no" && test "$PHP_ZLIB_DIR" != "yes"; then
72 + if test -f "$PHP_ZLIB_DIR/include/zlib/zlib.h"; then
73 + PHP_ZLIB_DIR="$PHP_ZLIB_DIR"
74 + PHP_ZLIB_INCDIR="$PHP_ZLIB_DIR/include/zlib"
75 + elif test -f "$PHP_ZLIB_DIR/include/zlib.h"; then
76 + PHP_ZLIB_DIR="$PHP_ZLIB_DIR"
77 + PHP_ZLIB_INCDIR="$PHP_ZLIB_DIR/include"
79 + AC_MSG_ERROR([Can not find zlib headers under "$PHP_ZLIB_DIR"])
84 + for i in /usr/local /usr; do
85 + if test -f "$i/include/zlib/zlib.h"; then
87 + PHP_ZLIB_INCDIR="$i/include/zlib"
88 + elif test -f "$i/include/zlib.h"; then
90 + PHP_ZLIB_INCDIR="$i/include"
96 - AC_MSG_CHECKING([for the location of zlib])
97 - if test "$PHP_ZLIB_DIR" = "no"; then
98 - AC_MSG_ERROR([zip support requires ZLIB. Use --with-zlib-dir=<DIR> to specify prefix where ZLIB include and library are located])
100 - AC_MSG_RESULT([$PHP_ZLIB_DIR])
101 - PHP_ADD_LIBRARY_WITH_PATH(z, $PHP_ZLIB_DIR/$PHP_LIBDIR, ZIP_SHARED_LIBADD)
102 - PHP_ADD_INCLUDE($PHP_ZLIB_INCDIR)
105 + AC_MSG_CHECKING([for the location of zlib])
106 + if test "$PHP_ZLIB_DIR" = "no"; then
107 + AC_MSG_ERROR([zip support requires ZLIB. Use --with-zlib-dir=<DIR> to specify prefix where ZLIB include and library are located])
109 + AC_MSG_RESULT([$PHP_ZLIB_DIR])
110 + PHP_ADD_LIBRARY_WITH_PATH(z, $PHP_ZLIB_DIR/$PHP_LIBDIR, ZIP_SHARED_LIBADD)
111 + PHP_ADD_INCLUDE($PHP_ZLIB_INCDIR)
114 - dnl This is PECL build, check if bundled PCRE library is used
115 - old_CPPFLAGS=$CPPFLAGS
118 + dnl This is PECL build, check if bundled PCRE library is used
119 + old_CPPFLAGS=$CPPFLAGS
122 #include <main/php_config.h>
123 #if defined(HAVE_BUNDLED_PCRE) && !defined(COMPILE_DL_PCRE)
134 #include <main/php_config.h>
135 #if defined(HAVE_PCRE) && !defined(COMPILE_DL_PCRE)
139 - PHP_PCRE_REGEX=pecl
143 + PHP_PCRE_REGEX=pecl
149 - CPPFLAGS=$old_CPPFLAGS
150 + CPPFLAGS=$old_CPPFLAGS
152 - PHP_ZIP_SOURCES="$PHP_ZIP_SOURCES lib/zip_add.c lib/zip_error.c lib/zip_fclose.c \
153 + PHP_ZIP_SOURCES="$PHP_ZIP_SOURCES lib/zip_add.c lib/zip_error.c lib/zip_fclose.c \
154 lib/zip_fread.c lib/zip_open.c lib/zip_source_filep.c \
155 lib/zip_strerror.c lib/zip_close.c lib/zip_error_get.c \
156 lib/zip_file_error_get.c lib/zip_free.c lib/zip_rename.c \
157 @@ -98,10 +138,11 @@ yes
158 lib/zip_source_open.c lib/zip_source_pkware.c lib/zip_source_pop.c \
159 lib/zip_source_read.c lib/zip_source_stat.c"
161 - AC_DEFINE(HAVE_ZIP,1,[ ])
162 - PHP_NEW_EXTENSION(zip, php_zip.c zip_stream.c $PHP_ZIP_SOURCES, $ext_shared)
163 - PHP_ADD_BUILD_DIR($ext_builddir/lib, 1)
164 - PHP_SUBST(ZIP_SHARED_LIBADD)
165 + AC_DEFINE(HAVE_ZIP,1,[ ])
166 + PHP_NEW_EXTENSION(zip, php_zip.c zip_stream.c $PHP_ZIP_SOURCES, $ext_shared)
167 + PHP_ADD_BUILD_DIR($ext_builddir/lib, 1)
168 + PHP_SUBST(ZIP_SHARED_LIBADD)
171 dnl so we always include the known-good working hack.
172 PHP_ADD_MAKEFILE_FRAGMENT
173 diff -up php-5.4.5RC1/ext/zip/php_zip.c.systzip php-5.4.5RC1/ext/zip/php_zip.c
174 --- php-5.4.5RC1/ext/zip/php_zip.c.systzip 2012-07-04 07:43:14.000000000 +0200
175 +++ php-5.4.5RC1/ext/zip/php_zip.c 2012-07-07 15:59:12.728676026 +0200
177 #include "ext/standard/php_string.h"
178 #include "ext/pcre/php_pcre.h"
180 +#if defined(HAVE_LIBZIP)
183 +/* Copied from libzip 0.10 */
185 +/* state of change of a file in zip archive */
187 +enum zip_state { ZIP_ST_UNCHANGED, ZIP_ST_DELETED, ZIP_ST_REPLACED,
188 + ZIP_ST_ADDED, ZIP_ST_RENAMED };
190 +/* error source for layered sources */
192 +enum zip_les { ZIP_LES_NONE, ZIP_LES_UPPER, ZIP_LES_LOWER, ZIP_LES_INVAL };
194 +typedef zip_int64_t (*zip_source_layered_callback)(struct zip_source *, void *,
195 + void *, zip_uint64_t,
196 + enum zip_source_cmd);
199 + int zip_err; /* libzip error code (ZIP_ER_*) */
200 + int sys_err; /* copy of errno (E*) or zlib error code */
201 + char *str; /* string representation or NULL */
204 +/* zip archive, part of API */
207 + char *zn; /* file name */
208 + FILE *zp; /* file */
209 + struct zip_error error; /* error information */
211 + unsigned int flags; /* archive global flags */
212 + unsigned int ch_flags; /* changed archive global flags */
214 + char *default_password; /* password used when no other supplied */
216 + struct zip_cdir *cdir; /* central directory */
217 + char *ch_comment; /* changed archive comment */
218 + int ch_comment_len; /* length of changed zip archive
219 + * comment, -1 if unchanged */
220 + zip_uint64_t nentry; /* number of entries */
221 + zip_uint64_t nentry_alloc; /* number of entries allocated */
222 + struct zip_entry *entry; /* entries */
223 + int nfile; /* number of opened files within archive */
224 + int nfile_alloc; /* number of files allocated */
225 + struct zip_file **file; /* opened files within archive */
228 +/* file in zip archive, part of API */
231 + struct zip *za; /* zip archive containing this file */
232 + struct zip_error error; /* error information */
234 + struct zip_source *src; /* data source */
237 +/* zip archive directory entry (central or local) */
240 + unsigned short version_madeby; /* (c) version of creator */
241 + unsigned short version_needed; /* (cl) version needed to extract */
242 + unsigned short bitflags; /* (cl) general purpose bit flag */
243 + unsigned short comp_method; /* (cl) compression method used */
244 + time_t last_mod; /* (cl) time of last modification */
245 + unsigned int crc; /* (cl) CRC-32 of uncompressed data */
246 + unsigned int comp_size; /* (cl) size of commpressed data */
247 + unsigned int uncomp_size; /* (cl) size of uncommpressed data */
248 + char *filename; /* (cl) file name (NUL-terminated) */
249 + unsigned short filename_len; /* (cl) length of filename (w/o NUL) */
250 + char *extrafield; /* (cl) extra field */
251 + unsigned short extrafield_len; /* (cl) length of extra field */
252 + char *comment; /* (c) file comment */
253 + unsigned short comment_len; /* (c) length of file comment */
254 + unsigned short disk_number; /* (c) disk number start */
255 + unsigned short int_attrib; /* (c) internal file attributes */
256 + unsigned int ext_attrib; /* (c) external file attributes */
257 + unsigned int offset; /* (c) offset of local header */
260 +/* zip archive central directory */
263 + struct zip_dirent *entry; /* directory entries */
264 + int nentry; /* number of entries */
266 + unsigned int size; /* size of central direcotry */
267 + unsigned int offset; /* offset of central directory in file */
268 + char *comment; /* zip archive comment */
269 + unsigned short comment_len; /* length of zip archive comment */
273 + struct zip_source *src;
275 + zip_source_callback f;
276 + zip_source_layered_callback l;
279 + enum zip_les error_source;
283 +/* entry in zip archive directory */
286 + enum zip_state state;
287 + struct zip_source *source;
292 + int ch_comment_len;
295 +void _zip_dirent_finalize(struct zip_dirent *zde)
297 + free(zde->filename);
298 + zde->filename = NULL;
299 + free(zde->extrafield);
300 + zde->extrafield = NULL;
301 + free(zde->comment);
302 + zde->comment = NULL;
305 +void _zip_cdir_free(struct zip_cdir *cd)
312 + for (i=0; i<cd->nentry; i++)
313 + _zip_dirent_finalize(cd->entry+i);
319 +void _zip_error_fini(struct zip_error *err)
325 +void _zip_error_init(struct zip_error *err)
327 + err->zip_err = ZIP_ER_OK;
332 +void _zip_unchange_data(struct zip_entry *ze)
335 + zip_source_free(ze->source);
339 + ze->state = ze->ch_filename ? ZIP_ST_RENAMED : ZIP_ST_UNCHANGED;
342 +void _zip_entry_free(struct zip_entry *ze)
344 + free(ze->ch_filename);
345 + ze->ch_filename = NULL;
346 + free(ze->ch_extra);
347 + ze->ch_extra = NULL;
348 + ze->ch_extra_len = -1;
349 + free(ze->ch_comment);
350 + ze->ch_comment = NULL;
351 + ze->ch_comment_len = -1;
353 + _zip_unchange_data(ze);
357 +_zip_error_set(struct zip_error *err, int ze, int se)
365 +void _zip_free(struct zip *za)
378 + free(za->default_password);
379 + _zip_cdir_free(za->cdir);
380 + free(za->ch_comment);
383 + for (i=0; i<za->nentry; i++) {
384 + _zip_entry_free(za->entry+i);
389 + for (i=0; i<za->nfile; i++) {
390 + if (za->file[i]->error.zip_err == ZIP_ER_OK) {
391 + _zip_error_set(&za->file[i]->error, ZIP_ER_ZIPCLOSED, 0);
392 + za->file[i]->za = NULL;
404 #include "lib/zipint.h"
407 /* zip_open is a macro for renaming libzip zipopen, so we need to use PHP_NAMED_FUNCTION */
408 static PHP_NAMED_FUNCTION(zif_zip_open);
409 @@ -1624,6 +1848,10 @@ static ZIPARCHIVE_METHOD(addEmptyDir)
412 idx = zip_stat(intern, s, 0, &sb);
413 + /* We don't care about the NOENT status error here. */
414 + if (intern->error.zip_err == ZIP_ER_NOENT) {
415 + _zip_error_set(&intern->error, ZIP_ER_OK, 0);
420 @@ -1846,6 +2074,10 @@ static ZIPARCHIVE_METHOD(addFromString)
423 cur_idx = zip_name_locate(intern, (const char *)name, 0);
424 + /* We don't care about the NOENT status error here. */
425 + if (intern->error.zip_err == ZIP_ER_NOENT) {
426 + _zip_error_set(&intern->error, ZIP_ER_OK, 0);
428 /* TODO: fix _zip_replace */
430 if (zip_delete(intern, cur_idx) == -1) {
431 @@ -2868,7 +3100,11 @@ static PHP_MINFO_FUNCTION(zip)
432 php_info_print_table_row(2, "Zip", "enabled");
433 php_info_print_table_row(2, "Extension Version","$Id$");
434 php_info_print_table_row(2, "Zip version", PHP_ZIP_VERSION_STRING);
435 - php_info_print_table_row(2, "Libzip version", LIBZIP_VERSION);
436 +#if defined(HAVE_LIBZIP)
437 + php_info_print_table_row(2, "Compiled against libzip version", LIBZIP_VERSION);
439 + php_info_print_table_row(2, "Bundled libzip version", LIBZIP_VERSION);
442 php_info_print_table_end();
444 diff -up php-5.4.5RC1/ext/zip/php_zip.h.systzip php-5.4.5RC1/ext/zip/php_zip.h
445 --- php-5.4.5RC1/ext/zip/php_zip.h.systzip 2012-07-04 07:43:14.000000000 +0200
446 +++ php-5.4.5RC1/ext/zip/php_zip.h 2012-07-07 15:57:34.845319432 +0200
447 @@ -28,7 +28,11 @@ extern zend_module_entry zip_module_entr
451 +#if defined(HAVE_LIBZIP)
457 #define PHP_ZIP_VERSION_STRING "1.11.0"
459 diff -up php-5.4.5RC1/ext/zip/tests/bug38943.phpt.systzip php-5.4.5RC1/ext/zip/tests/bug38943.phpt
460 --- php-5.4.5RC1/ext/zip/tests/bug38943.phpt.systzip 2012-07-04 07:43:14.000000000 +0200
461 +++ php-5.4.5RC1/ext/zip/tests/bug38943.phpt 2012-07-07 15:56:41.422171242 +0200
462 @@ -27,7 +27,7 @@ array(1) {
466 -object(myZip)#1 (%d) {
467 +object(myZip)#%d (%d) {
468 ["test":"myZip":private]=>
471 diff -up php-5.4.5RC1/ext/zip/tests/pecl12414.phpt.systzip php-5.4.5RC1/ext/zip/tests/pecl12414.phpt
472 --- php-5.4.5RC1/ext/zip/tests/pecl12414.phpt.systzip 2012-07-04 07:43:14.000000000 +0200
473 +++ php-5.4.5RC1/ext/zip/tests/pecl12414.phpt 2012-07-07 15:56:41.422171242 +0200
474 @@ -5,6 +5,8 @@ Bug #12414 ( extracting files from damag
476 if(!extension_loaded('zip')) die('skip');
479 +Doesn't work with system libzip (zip_readfile could not read from ...)
482 $filename = 'MYLOGOV2.GFX';
483 diff -up php-5.4.5RC1/ext/zip/zip_stream.c.systzip php-5.4.5RC1/ext/zip/zip_stream.c
484 --- php-5.4.5RC1/ext/zip/zip_stream.c.systzip 2012-07-04 07:43:14.000000000 +0200
485 +++ php-5.4.5RC1/ext/zip/zip_stream.c 2012-07-07 15:56:41.423171244 +0200
490 +#if defined(HAVE_LIBZIP)
496 #include "php_streams.h"
497 #include "ext/standard/file.h"