Skip to content

Commit 4bcb68a

Browse files
author
Greg Beaver
committed
fix errors found in delMetaData(), add get/delMetaData() to MetaData read test
1 parent 4f34a69 commit 4bcb68a

File tree

6 files changed

+109
-26
lines changed

6 files changed

+109
-26
lines changed

ext/phar/config.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ PHP_ARG_ENABLE(phar, for phar support/phar zlib support,
66

77
if test "$PHP_PHAR" != "no"; then
88
PHP_NEW_EXTENSION(phar, phar.c phar_object.c phar_path_check.c, $ext_shared)
9-
PHP_ADD_EXTENSION_DEP(phar, zlib, true)
9+
PHP_ADD_EXTENSION_DEP(phar, zlib, false)
1010
PHP_ADD_EXTENSION_DEP(phar, bz2, false)
1111
PHP_ADD_EXTENSION_DEP(phar, spl, false)
1212
PHP_ADD_EXTENSION_DEP(phar, gnupg, false)

ext/phar/config.w32

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ARG_ENABLE("phar", "enable phar support", "no");
55

66
if (PHP_PHAR != "no") {
77
EXTENSION("phar", "phar.c phar_object.c phar_path_check.c");
8-
ADD_EXTENSION_DEP('phar', 'zlib', true);
8+
ADD_EXTENSION_DEP('phar', 'zlib', false);
99
ADD_EXTENSION_DEP('phar', 'bz2', false);
1010
ADD_EXTENSION_DEP('phar', 'spl', false);
1111
ADD_EXTENSION_DEP('phar', 'gnupg', false);

ext/phar/phar.c

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,14 @@ int phar_open_file(php_stream *fp, char *fname, int fname_len, char *alias, int
12411241
}
12421242
efree(entry.filename);
12431243
MAPPHAR_FAIL("zlib extension is required for gz compressed .phar file \"%s\"");
1244+
#else
1245+
if (!PHAR_G(has_zlib)) {
1246+
if (entry.metadata) {
1247+
zval_ptr_dtor(&entry.metadata);
1248+
}
1249+
efree(entry.filename);
1250+
MAPPHAR_FAIL("zlib extension is required for gz compressed .phar file \"%s\"");
1251+
}
12441252
#endif
12451253
break;
12461254
case PHAR_ENT_COMPRESSED_BZ2:
@@ -1251,7 +1259,11 @@ int phar_open_file(php_stream *fp, char *fname, int fname_len, char *alias, int
12511259
efree(entry.filename);
12521260
MAPPHAR_FAIL("bz2 extension is required for bzip2 compressed .phar file \"%s\"");
12531261
#else
1254-
if (!zend_hash_exists(&module_registry, "bz2", sizeof("bz2"))) {
1262+
if (!PHAR_G(has_bz2)) {
1263+
if (entry.metadata) {
1264+
zval_ptr_dtor(&entry.metadata);
1265+
}
1266+
efree(entry.filename);
12551267
MAPPHAR_FAIL("bz2 extension is required for bzip2 compressed .phar file \"%s\"");
12561268
}
12571269
#endif
@@ -3750,6 +3762,9 @@ PHP_MINIT_FUNCTION(phar) /* {{{ */
37503762
ZEND_INIT_MODULE_GLOBALS(phar, php_phar_init_globals_module, NULL);
37513763
REGISTER_INI_ENTRIES();
37523764

3765+
PHAR_G(has_gnupg) = zend_hash_exists(&module_registry, "gnupg", sizeof("gnupg"));
3766+
PHAR_G(has_bz2) = zend_hash_exists(&module_registry, "bz2", sizeof("bz2"));
3767+
PHAR_G(has_zlib) = zend_hash_exists(&module_registry, "zlib", sizeof("zlib"));
37533768
phar_object_init(TSRMLS_C);
37543769

37553770
return php_register_url_stream_wrapper("phar", &php_stream_phar_wrapper TSRMLS_CC);
@@ -3799,14 +3814,20 @@ PHP_MINFO_FUNCTION(phar) /* {{{ */
37993814
php_info_print_table_row(2, "Phar EXT version", PHAR_EXT_VERSION_STR);
38003815
php_info_print_table_row(2, "Phar API version", PHAR_API_VERSION_STR);
38013816
php_info_print_table_row(2, "CVS revision", "$Revision$");
3802-
php_info_print_table_row(2, "gzip compression",
38033817
#if HAVE_ZLIB
3804-
"enabled");
3818+
if (PHAR_G(has_zlib)) {
3819+
php_info_print_table_row(2, "gzip compression",
3820+
"enabled");
3821+
} else {
3822+
php_info_print_table_row(2, "gzip compression",
3823+
"disabled");
3824+
}
38053825
#else
3826+
php_info_print_table_row(2, "gzip compression",
38063827
"disabled");
38073828
#endif
38083829
#if HAVE_BZ2
3809-
if (!zend_hash_exists(&module_registry, "bz2", sizeof("bz2"))) {
3830+
if (PHAR_G(has_bz2)) {
38103831
php_info_print_table_row(2, "bzip2 compression",
38113832
"disabled");
38123833
} else {
@@ -3818,7 +3839,7 @@ PHP_MINFO_FUNCTION(phar) /* {{{ */
38183839
"disabled");
38193840
#endif
38203841
#if HAVE_GNUPGLIB
3821-
if (zend_hash_exists(&module_registry, "gnupg", sizeof("gnupg"))) {
3842+
if (PHAR_G(has_gnupg)) {
38223843
php_info_print_table_row(2, "GPG signature",
38233844
"enabled");
38243845
} else {
@@ -3845,12 +3866,12 @@ PHP_MINFO_FUNCTION(phar) /* {{{ */
38453866
*/
38463867
static zend_module_dep phar_deps[] = {
38473868
#if HAVE_ZLIB
3848-
ZEND_MOD_REQUIRED("zlib")
3869+
ZEND_MOD_OPTIONAL("zlib")
38493870
#endif
38503871
#if HAVE_BZ2
38513872
ZEND_MOD_OPTIONAL("bz2")
38523873
#endif
3853-
#if HAVE_GNUPG
3874+
#if HAVE_GNUPGLIB
38543875
ZEND_MOD_OPTIONAL("gnupg")
38553876
#endif
38563877
#if HAVE_SPL

ext/phar/phar_internal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ ZEND_BEGIN_MODULE_GLOBALS(phar)
114114
int require_hash;
115115
int request_done;
116116
int request_ends;
117+
int has_bz2:1;
118+
int has_gnupg:1;
119+
int has_zlib:1;
117120
ZEND_END_MODULE_GLOBALS(phar)
118121

119122
ZEND_EXTERN_MODULE_GLOBALS(phar)

ext/phar/phar_object.c

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -144,25 +144,29 @@ PHP_METHOD(Phar, canCompress)
144144
switch (method) {
145145
case PHAR_ENT_COMPRESSED_GZ:
146146
#if HAVE_ZLIB
147-
RETURN_TRUE;
147+
if (PHAR_G(has_zlib)) {
148+
RETURN_TRUE;
149+
} else {
150+
RETURN_FALSE;
151+
}
148152
#else
149153
RETURN_FALSE;
150154
#endif
151155

152156
case PHAR_ENT_COMPRESSED_BZ2:
153157
#if HAVE_BZ2
154-
if (zend_hash_exists(&module_registry, "bz2", sizeof("bz2"))) {
155-
RETURN_TRUE;
156-
} else {
157-
RETURN_FALSE;
158-
}
158+
if (PHAR_G(has_bz2)) {
159+
RETURN_TRUE;
160+
} else {
161+
RETURN_FALSE;
162+
}
159163
#else
160164
RETURN_FALSE;
161165
#endif
162166

163167
default:
164168
#if HAVE_ZLIB || HAVE_BZ2
165-
if (zend_hash_exists(&module_registry, "bz2", sizeof("bz2")) || HAVE_ZLIB) {
169+
if (PHAR_G(has_zlib) || PHAR_G(has_bz2)) {
166170
RETURN_TRUE;
167171
} else {
168172
RETURN_FALSE;
@@ -592,11 +596,13 @@ PHP_METHOD(Phar, getSupportedCompression)
592596
{
593597
array_init(return_value);
594598

595-
#if !HAVE_ZLIB
596-
add_next_index_stringl(return_value, "GZ", 2, 1);
599+
#if HAVE_ZLIB
600+
if (PHAR_G(has_zlib)) {
601+
add_next_index_stringl(return_value, "GZ", 2, 1);
602+
}
597603
#endif
598-
#if !HAVE_BZ2
599-
if (zend_hash_exists(&module_registry, "bz2", sizeof("bz2"))) {
604+
#if HAVE_BZ2
605+
if (PHAR_G(has_bz2)) {
600606
add_next_index_stringl(return_value, "BZIP2", 5, 1);
601607
}
602608
#endif
@@ -668,7 +674,11 @@ static int phar_test_compression(void *pDest, void *argument TSRMLS_DC) /* {{{ *
668674
return ZEND_HASH_APPLY_KEEP;
669675
}
670676
#if !HAVE_BZ2
671-
if (zend_hash_exists(&module_registry, "bz2", sizeof("bz2"))) {
677+
if (entry->flags & PHAR_ENT_COMPRESSED_BZ2) {
678+
*(int *) argument = 0;
679+
}
680+
#else
681+
if (!PHAR_G(has_bz2)) {
672682
if (entry->flags & PHAR_ENT_COMPRESSED_BZ2) {
673683
*(int *) argument = 0;
674684
}
@@ -678,6 +688,12 @@ static int phar_test_compression(void *pDest, void *argument TSRMLS_DC) /* {{{ *
678688
if (entry->flags & PHAR_ENT_COMPRESSED_GZ) {
679689
*(int *) argument = 0;
680690
}
691+
#else
692+
if (!PHAR_G(has_zlib)) {
693+
if (entry->flags & PHAR_ENT_COMPRESSED_GZ) {
694+
*(int *) argument = 0;
695+
}
696+
}
681697
#endif
682698
return ZEND_HASH_APPLY_KEEP;
683699
}
@@ -713,6 +729,10 @@ PHP_METHOD(Phar, compressAllFilesGZ)
713729
"Phar is readonly, cannot change compression");
714730
}
715731
#if HAVE_ZLIB
732+
if (!PHAR_G(has_zlib)) {
733+
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC,
734+
"Cannot compress with Gzip compression, zlib extension is not enabled");
735+
}
716736
if (!pharobj_cancompress(&phar_obj->arc.archive->manifest TSRMLS_CC)) {
717737
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC,
718738
"Cannot compress all files as Gzip, some are compressed as bzip2 and cannot be uncompressed");
@@ -747,7 +767,7 @@ PHP_METHOD(Phar, compressAllFilesBZIP2)
747767
"Phar is readonly, cannot change compression");
748768
}
749769
#if HAVE_BZ2
750-
if (!zend_hash_exists(&module_registry, "bz2", sizeof("bz2"))) {
770+
if (!PHAR_G(has_bz2)) {
751771
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC,
752772
"Cannot compress with Bzip2 compression, bz2 extension is not enabled");
753773
}
@@ -1067,7 +1087,7 @@ PHP_METHOD(Phar, delMetadata)
10671087
RETURN_TRUE;
10681088
}
10691089
} else {
1070-
RETURN_FALSE;
1090+
RETURN_TRUE;
10711091
}
10721092
}
10731093
/* }}} */
@@ -1377,7 +1397,7 @@ PHP_METHOD(PharFileInfo, delMetadata)
13771397
RETURN_TRUE;
13781398
}
13791399
} else {
1380-
RETURN_FALSE;
1400+
RETURN_TRUE;
13811401
}
13821402
}
13831403
/* }}} */
@@ -1407,6 +1427,10 @@ PHP_METHOD(PharFileInfo, setCompressedGZ)
14071427
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC,
14081428
"Cannot compress deleted file");
14091429
}
1430+
if (!PHAR_G(has_zlib)) {
1431+
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC,
1432+
"Cannot compress with Gzip compression, zlib extension is not enabled");
1433+
}
14101434
entry_obj->ent.entry->old_flags = entry_obj->ent.entry->flags;
14111435
entry_obj->ent.entry->flags &= ~PHAR_ENT_COMPRESSION_MASK;
14121436
entry_obj->ent.entry->flags |= PHAR_ENT_COMPRESSED_GZ;
@@ -1435,7 +1459,7 @@ PHP_METHOD(PharFileInfo, setCompressedBZIP2)
14351459
char *error;
14361460
PHAR_ENTRY_OBJECT();
14371461

1438-
if (!zend_hash_exists(&module_registry, "bz2", sizeof("bz2"))) {
1462+
if (!PHAR_G(has_bz2)) {
14391463
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC,
14401464
"Cannot compress with Bzip2 compression, bz2 extension is not enabled");
14411465
}
@@ -1504,14 +1528,19 @@ PHP_METHOD(PharFileInfo, setUncompressed)
15041528
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC,
15051529
"Cannot uncompress Gzip-compressed file, zlib extension is not enabled");
15061530
}
1531+
#else
1532+
if (!PHAR_G(has_zlib)) {
1533+
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC,
1534+
"Cannot uncompress Gzip-compressed file, zlib extension is not enabled");
1535+
}
15071536
#endif
15081537
#if !HAVE_BZ2
15091538
if (entry_obj->ent.entry->flags & PHAR_ENT_COMPRESSED_BZ2) {
15101539
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC,
15111540
"Cannot uncompress Bzip2-compressed file, bzip2 extension is not enabled");
15121541
}
15131542
#else
1514-
if (!zend_hash_exists(&module_registry, "bz2", sizeof("bz2"))) {
1543+
if (!PHAR_G(has_bz2)) {
15151544
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC,
15161545
"Cannot uncompress Bzip2-compressed file, bzip2 extension is not enabled");
15171546
}

ext/phar/tests/phar_metadata_read.phpt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,17 @@ foreach($files as $name => $cont) {
2323
}
2424

2525
$phar = new Phar($fname);
26+
var_dump($phar->hasMetaData());
27+
var_dump($phar->getMetaData());
28+
var_dump($phar->delMetaData());
29+
var_dump($phar->getMetaData());
30+
var_dump($phar->delMetaData());
2631
var_dump($phar->getMetaData());
2732
foreach($files as $name => $cont) {
33+
echo " meta $name\n";
34+
var_dump($phar[$name]->hasMetadata());
35+
var_dump($phar[$name]->getMetadata());
36+
var_dump($phar[$name]->delMetadata());
2837
var_dump($phar[$name]->getMetadata());
2938
}
3039

@@ -42,21 +51,42 @@ string(1) "a"
4251
string(1) "b"
4352
string(1) "c"
4453
string(1) "d"
54+
bool(true)
4555
string(8) "hi there"
56+
bool(true)
57+
NULL
58+
bool(true)
59+
NULL
60+
meta a
61+
bool(false)
4662
NULL
63+
bool(true)
4764
NULL
65+
meta b
66+
bool(false)
67+
NULL
68+
bool(true)
69+
NULL
70+
meta c
71+
bool(true)
4872
array(2) {
4973
[0]=>
5074
string(2) "hi"
5175
[1]=>
5276
string(5) "there"
5377
}
78+
bool(true)
79+
NULL
80+
meta d
81+
bool(true)
5482
array(2) {
5583
["hi"]=>
5684
string(5) "there"
5785
["foo"]=>
5886
string(3) "bar"
5987
}
88+
bool(true)
89+
NULL
6090
string(1) "a"
6191
string(1) "b"
6292
string(1) "c"

0 commit comments

Comments
 (0)