Skip to content

Commit f57526a

Browse files
committed
Store base path as zend_string in Phar::buildFrom*
This also removes the need to check for length overflow, as the length is now size_t.
1 parent 8c192c7 commit f57526a

File tree

1 file changed

+11
-25
lines changed

1 file changed

+11
-25
lines changed

Diff for: ext/phar/phar_object.c

+11-25
Original file line numberDiff line numberDiff line change
@@ -1359,10 +1359,9 @@ PHP_METHOD(Phar, __destruct)
13591359
struct _phar_t {
13601360
phar_archive_object *p;
13611361
zend_class_entry *c;
1362-
char *b;
1362+
zend_string *base;
13631363
zval *ret;
13641364
php_stream *fp;
1365-
uint32_t l;
13661365
int count;
13671366
};
13681367

@@ -1371,12 +1370,12 @@ static int phar_build(zend_object_iterator *iter, void *puser) /* {{{ */
13711370
zval *value;
13721371
bool close_fp = 1;
13731372
struct _phar_t *p_obj = (struct _phar_t*) puser;
1374-
size_t str_key_len, base_len = p_obj->l;
1373+
size_t str_key_len, base_len = ZSTR_LEN(p_obj->base);
13751374
phar_entry_data *data;
13761375
php_stream *fp;
13771376
size_t fname_len;
13781377
size_t contents_len;
1379-
char *fname, *error = NULL, *base = p_obj->b, *save = NULL, *temp = NULL;
1378+
char *fname, *error = NULL, *base = ZSTR_VAL(p_obj->base), *save = NULL, *temp = NULL;
13801379
zend_string *opened;
13811380
char *str_key;
13821381
zend_class_entry *ce = p_obj->c;
@@ -1686,14 +1685,13 @@ static int phar_build(zend_object_iterator *iter, void *puser) /* {{{ */
16861685
*/
16871686
PHP_METHOD(Phar, buildFromDirectory)
16881687
{
1689-
char *dir, *error;
1690-
size_t dir_len;
1688+
char *error;
16911689
bool apply_reg = 0;
16921690
zval arg, arg2, iter, iteriter, regexiter;
16931691
struct _phar_t pass;
1694-
zend_string *regex = NULL;
1692+
zend_string *dir, *regex = NULL;
16951693

1696-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|S", &dir, &dir_len, &regex) == FAILURE) {
1694+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|S", &dir, &regex) == FAILURE) {
16971695
RETURN_THROWS();
16981696
}
16991697

@@ -1705,23 +1703,18 @@ PHP_METHOD(Phar, buildFromDirectory)
17051703
RETURN_THROWS();
17061704
}
17071705

1708-
if (ZEND_SIZE_T_UINT_OVFL(dir_len)) {
1709-
RETURN_FALSE;
1710-
}
1711-
17121706
if (SUCCESS != object_init_ex(&iter, spl_ce_RecursiveDirectoryIterator)) {
17131707
zval_ptr_dtor(&iter);
17141708
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Unable to instantiate directory iterator for %s", phar_obj->archive->fname);
17151709
RETURN_THROWS();
17161710
}
17171711

1718-
ZVAL_STRINGL(&arg, dir, dir_len);
1712+
ZVAL_STR(&arg, dir);
17191713
ZVAL_LONG(&arg2, SPL_FILE_DIR_SKIPDOTS|SPL_FILE_DIR_UNIXPATHS);
17201714

17211715
zend_call_known_instance_method_with_2_params(spl_ce_RecursiveDirectoryIterator->constructor,
17221716
Z_OBJ(iter), NULL, &arg, &arg2);
17231717

1724-
zval_ptr_dtor(&arg);
17251718
if (EG(exception)) {
17261719
zval_ptr_dtor(&iter);
17271720
RETURN_THROWS();
@@ -1764,8 +1757,7 @@ PHP_METHOD(Phar, buildFromDirectory)
17641757

17651758
pass.c = apply_reg ? Z_OBJCE(regexiter) : Z_OBJCE(iteriter);
17661759
pass.p = phar_obj;
1767-
pass.b = dir;
1768-
pass.l = (uint32_t)dir_len;
1760+
pass.base = dir;
17691761
pass.count = 0;
17701762
pass.ret = return_value;
17711763
pass.fp = php_stream_fopen_tmpfile();
@@ -1822,11 +1814,10 @@ PHP_METHOD(Phar, buildFromIterator)
18221814
{
18231815
zval *obj;
18241816
char *error;
1825-
size_t base_len = 0;
1826-
char *base = NULL;
1817+
zend_string *base = ZSTR_EMPTY_ALLOC();
18271818
struct _phar_t pass;
18281819

1829-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|s!", &obj, zend_ce_traversable, &base, &base_len) == FAILURE) {
1820+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|S!", &obj, zend_ce_traversable, &base) == FAILURE) {
18301821
RETURN_THROWS();
18311822
}
18321823

@@ -1838,10 +1829,6 @@ PHP_METHOD(Phar, buildFromIterator)
18381829
RETURN_THROWS();
18391830
}
18401831

1841-
if (ZEND_SIZE_T_UINT_OVFL(base_len)) {
1842-
RETURN_FALSE;
1843-
}
1844-
18451832
if (phar_obj->archive->is_persistent && FAILURE == phar_copy_on_write(&(phar_obj->archive))) {
18461833
zend_throw_exception_ex(phar_ce_PharException, 0, "phar \"%s\" is persistent, unable to copy on write", phar_obj->archive->fname);
18471834
RETURN_THROWS();
@@ -1851,8 +1838,7 @@ PHP_METHOD(Phar, buildFromIterator)
18511838

18521839
pass.c = Z_OBJCE_P(obj);
18531840
pass.p = phar_obj;
1854-
pass.b = base;
1855-
pass.l = (uint32_t)base_len;
1841+
pass.base = base;
18561842
pass.ret = return_value;
18571843
pass.count = 0;
18581844
pass.fp = php_stream_fopen_tmpfile();

0 commit comments

Comments
 (0)