Skip to content

Commit e00cb38

Browse files
committed
Review comments
1 parent 4b3817d commit e00cb38

4 files changed

Lines changed: 29 additions & 23 deletions

File tree

ext/bz2/bz2_filter.c

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -396,36 +396,42 @@ static php_stream_filter *php_bz2_decompress_filter_create(zval *filter_params,
396396
bool expect_concatenated = false;
397397

398398
if (filter_params) {
399-
if (Z_TYPE_P(filter_params) == IS_TRUE || Z_TYPE_P(filter_params) == IS_FALSE) {
400-
small_footprint = Z_TYPE_P(filter_params) == IS_TRUE;
401-
goto allocate_decompress_filter;
402-
}
403-
if (UNEXPECTED(Z_TYPE_P(filter_params) != IS_ARRAY && Z_TYPE_P(filter_params) != IS_OBJECT)) {
399+
if (UNEXPECTED(
400+
Z_TYPE_P(filter_params) != IS_TRUE
401+
&& Z_TYPE_P(filter_params) != IS_FALSE
402+
&& Z_TYPE_P(filter_params) != IS_ARRAY
403+
&& Z_TYPE_P(filter_params) != IS_OBJECT
404+
)) {
404405
php_error_docref(NULL, E_WARNING,
405-
"Filter parameters for bzip2.decompress filter must be of type array|bool, %s given",
406+
"Filter parameters for bzip2.decompress filter must be of type array|object|bool, %s given",
406407
zend_zval_type_name(filter_params)
407408
);
408409
return NULL;
409410
}
410411

411-
const HashTable *filter_params_ht = HASH_OF(filter_params);
412-
/* TODO: convert php_stream_filter_parse_write_seek_mode() to take HashTable */
413-
if (php_stream_filter_parse_write_seek_mode(filter_params, &write_seekable) == FAILURE) {
414-
return NULL;
415-
}
412+
if (Z_TYPE_P(filter_params) == IS_TRUE || Z_TYPE_P(filter_params) == IS_FALSE) {
413+
small_footprint = Z_TYPE_P(filter_params) == IS_TRUE;
414+
} else {
415+
ZEND_ASSERT(Z_TYPE_P(filter_params) == IS_ARRAY || Z_TYPE_P(filter_params) == IS_OBJECT);
416416

417-
const zval *concatenated = zend_hash_str_find_ind(filter_params_ht, ZEND_STRL("concatenated"));
418-
if (concatenated) {
419-
expect_concatenated = zend_is_true(concatenated);
420-
}
417+
const HashTable *filter_params_ht = HASH_OF(filter_params);
418+
/* TODO: convert php_stream_filter_parse_write_seek_mode() to take HashTable */
419+
if (php_stream_filter_parse_write_seek_mode(filter_params, &write_seekable) == FAILURE) {
420+
return NULL;
421+
}
422+
423+
const zval *concatenated = zend_hash_str_find_ind(filter_params_ht, ZEND_STRL("concatenated"));
424+
if (concatenated) {
425+
expect_concatenated = zend_is_true(concatenated);
426+
}
421427

422-
const zval *small = zend_hash_str_find_ind(filter_params_ht, ZEND_STRL("small"));
423-
if (small) {
424-
small_footprint = zend_is_true(small);
428+
const zval *small = zend_hash_str_find_ind(filter_params_ht, ZEND_STRL("small"));
429+
if (small) {
430+
small_footprint = zend_is_true(small);
431+
}
425432
}
426433
}
427434

428-
allocate_decompress_filter:;
429435
php_bz2_filter_data *data = php_bz2_filter_data_new(persistent);
430436
/* Save configuration for reset */
431437
data->small_footprint = small_footprint;
@@ -443,7 +449,7 @@ static php_stream_filter *php_bz2_compress_filter_create(zval *filter_params, bo
443449
if (filter_params) {
444450
if (UNEXPECTED(Z_TYPE_P(filter_params) != IS_ARRAY && Z_TYPE_P(filter_params) != IS_OBJECT)) {
445451
php_error_docref(NULL, E_WARNING,
446-
"Filter parameters for bzip2.compress filter must be of type array, %s given",
452+
"Filter parameters for bzip2.compress filter must be of type array|object, %s given",
447453
zend_zval_type_name(filter_params)
448454
);
449455
return NULL;

ext/bz2/tests/bz2_filter_compress_errors.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fclose($fp);
3131

3232
?>
3333
--EXPECTF--
34-
Warning: stream_filter_append(): Filter parameters for bzip2.compress filter must be of type array, string given in %s on line %d
34+
Warning: stream_filter_append(): Filter parameters for bzip2.compress filter must be of type array|object, string given in %s on line %d
3535

3636
Warning: stream_filter_append(): Unable to create or locate filter "bzip2.compress" in %s on line %d
3737
bool(false)

ext/bz2/tests/bz2_filter_decompress_errors.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fclose($fp);
1313

1414
?>
1515
--EXPECTF--
16-
Warning: stream_filter_append(): Filter parameters for bzip2.decompress filter must be of type array|bool, string given in %s on line %d
16+
Warning: stream_filter_append(): Filter parameters for bzip2.decompress filter must be of type array|object|bool, string given in %s on line %d
1717

1818
Warning: stream_filter_append(): Unable to create or locate filter "bzip2.decompress" in %s on line %d
1919
bool(false)

ext/bz2/tests/bz2_filter_unknown_errors.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
bzip2.decompress filter param errors
2+
bzip2 filter error on unknown filter name
33
--EXTENSIONS--
44
bz2
55
--FILE--

0 commit comments

Comments
 (0)