Skip to content

Commit 23e721f

Browse files
committed
Fix #73054: default option ignored when object passed to int filter
If an object that can't be converted to string is validated, we must not bail out early, but rather check for a requested default value.
1 parent cb91a51 commit 23e721f

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ PHP NEWS
1111
FILTER_FLAG_NO_PRIV_RANGE). (julien)
1212
. Fixed bug #67167 (Wrong return value from FILTER_VALIDATE_BOOLEAN,
1313
FILTER_NULL_ON_FAILURE). (levim, cmb)
14+
. Fixed bug #73054 (default option ignored when object passed to int filter).
15+
(cmb)
1416

1517
- GD:
1618
. Fixed bug #67325 (imagetruecolortopalette: white is duplicated in palette).

ext/filter/filter.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,14 +380,14 @@ static void php_zval_filter(zval **value, long filter, long flags, zval *options
380380

381381
ce = Z_OBJCE_PP(value);
382382
if (!ce->__tostring) {
383-
zval_ptr_dtor(value);
383+
zval_dtor(*value);
384384
/* #67167: doesn't return null on failure for objects */
385385
if (flags & FILTER_NULL_ON_FAILURE) {
386386
ZVAL_NULL(*value);
387387
} else {
388388
ZVAL_FALSE(*value);
389389
}
390-
return;
390+
goto handle_default;
391391
}
392392
}
393393

@@ -396,6 +396,7 @@ static void php_zval_filter(zval **value, long filter, long flags, zval *options
396396

397397
filter_func.function(*value, flags, options, charset TSRMLS_CC);
398398

399+
handle_default:
399400
if (
400401
options && (Z_TYPE_P(options) == IS_ARRAY || Z_TYPE_P(options) == IS_OBJECT) &&
401402
((flags & FILTER_NULL_ON_FAILURE && Z_TYPE_PP(value) == IS_NULL) ||

ext/filter/tests/bug73054.phpt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
Bug #73054 (default option ignored when object passed to int filter)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('filter')) die('skip filter extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
var_dump(
10+
filter_var(new stdClass, FILTER_VALIDATE_INT, [
11+
'options' => ['default' => 2],
12+
]),
13+
filter_var(new stdClass, FILTER_VALIDATE_INT, [
14+
'options' => ['default' => 2],
15+
'flags' => FILTER_NULL_ON_FAILURE
16+
])
17+
);
18+
?>
19+
===DONE===
20+
--EXPECT--
21+
int(2)
22+
int(2)
23+
===DONE===

0 commit comments

Comments
 (0)