Skip to content

Throw exception for unconstructed intl objects #5052

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ext/intl/breakiterator/breakiterator_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ static inline BreakIterator_object *php_intl_breakiterator_fetch_object(zend_obj
BREAKITER_METHOD_FETCH_OBJECT_NO_CHECK; \
if (bio->biter == NULL) \
{ \
intl_errors_set(&bio->err, U_ILLEGAL_ARGUMENT_ERROR, "Found unconstructed BreakIterator", 0); \
RETURN_FALSE; \
zend_throw_error(NULL, "Found unconstructed BreakIterator"); \
RETURN_THROWS(); \
}

void breakiterator_object_create(zval *object, BreakIterator *break_iter, int brand_new);
Expand Down
4 changes: 2 additions & 2 deletions ext/intl/calendar/calendar_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ static inline Calendar_object *php_intl_calendar_fetch_object(zend_object *obj)
CALENDAR_METHOD_FETCH_OBJECT_NO_CHECK; \
if (co->ucal == NULL) \
{ \
intl_errors_set(&co->err, U_ILLEGAL_ARGUMENT_ERROR, "Found unconstructed IntlCalendar", 0); \
RETURN_FALSE; \
zend_throw_error(NULL, "Found unconstructed IntlCalendar"); \
RETURN_THROWS(); \
}

void calendar_object_create(zval *object, Calendar *calendar);
Expand Down
4 changes: 2 additions & 2 deletions ext/intl/common/common_enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ extern "C" {
object = ZEND_THIS; \
INTLITERATOR_METHOD_FETCH_OBJECT_NO_CHECK; \
if (ii->iterator == NULL) { \
intl_errors_set(&ii->err, U_ILLEGAL_ARGUMENT_ERROR, "Found unconstructed IntlIterator", 0); \
RETURN_FALSE; \
zend_throw_error(NULL, "Found unconstructed IntlIterator"); \
RETURN_THROWS(); \
}

typedef struct {
Expand Down
4 changes: 2 additions & 2 deletions ext/intl/dateformat/dateformat_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ extern zend_class_entry *IntlDateFormatter_ce_ptr;
DATE_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK; \
if (dfo->datef_data.udatf == NULL) \
{ \
intl_errors_set(&dfo->datef_data.error, U_ILLEGAL_ARGUMENT_ERROR, "Found unconstructed IntlDateFormatter", 0); \
RETURN_FALSE; \
zend_throw_error(NULL, "Found unconstructed IntlDateFormatter"); \
RETURN_THROWS(); \
}

#define DATE_FORMAT_OBJECT(dfo) (dfo)->datef_data.udatf
Expand Down
5 changes: 2 additions & 3 deletions ext/intl/formatter/formatter_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ extern zend_class_entry *NumberFormatter_ce_ptr;
FORMATTER_METHOD_FETCH_OBJECT_NO_CHECK; \
if (FORMATTER_OBJECT(nfo) == NULL) \
{ \
intl_errors_set(&nfo->nf_data.error, U_ILLEGAL_ARGUMENT_ERROR, \
"Found unconstructed NumberFormatter", 0); \
RETURN_FALSE; \
zend_throw_error(NULL, "Found unconstructed NumberFormatter"); \
RETURN_THROWS(); \
}


Expand Down
5 changes: 2 additions & 3 deletions ext/intl/msgformat/msgformat_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ extern zend_class_entry *MessageFormatter_ce_ptr;
#define MSG_FORMAT_METHOD_FETCH_OBJECT \
MSG_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK; \
if (MSG_FORMAT_OBJECT(mfo) == NULL) { \
intl_errors_set(&mfo->mf_data.error, U_ILLEGAL_ARGUMENT_ERROR, \
"Found unconstructed MessageFormatter", 0); \
RETURN_FALSE; \
zend_throw_error(NULL, "Found unconstructed MessageFormatter"); \
RETURN_THROWS(); \
}

#define MSG_FORMAT_OBJECT(mfo) (mfo)->mf_data.umsgf
Expand Down
4 changes: 2 additions & 2 deletions ext/intl/resourcebundle/resourcebundle.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static function create(?string $locale, ?string $bundlename, bool $fallba
*/
public function get($index, bool $fallback = true) {}

/** @return int|false */
/** @return int */
public function count() {}

/** @return array|false */
Expand All @@ -34,7 +34,7 @@ function resourcebundle_create(?string $locale, ?string $bundlename, bool $fallb
*/
function resourcebundle_get(ResourceBundle $bundle, $index) {}

function resourcebundle_count(ResourceBundle $bundle): int|false {}
function resourcebundle_count(ResourceBundle $bundle): int {}

function resourcebundle_locales(string $bundlename): array|false {}

Expand Down
6 changes: 2 additions & 4 deletions ext/intl/resourcebundle/resourcebundle_arginfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,15 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_resourcebundle_get, 0, 0, 2)
ZEND_ARG_INFO(0, index)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_resourcebundle_count, 0, 1, MAY_BE_LONG|MAY_BE_FALSE)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_resourcebundle_count, 0, 1, IS_LONG, 0)
ZEND_ARG_OBJ_INFO(0, bundle, ResourceBundle, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_resourcebundle_locales, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, bundlename, IS_STRING, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_resourcebundle_get_error_code, 0, 1, IS_LONG, 0)
ZEND_ARG_OBJ_INFO(0, bundle, ResourceBundle, 0)
ZEND_END_ARG_INFO()
#define arginfo_resourcebundle_get_error_code arginfo_resourcebundle_count

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_resourcebundle_get_error_message, 0, 1, IS_STRING, 0)
ZEND_ARG_OBJ_INFO(0, bundle, ResourceBundle, 0)
Expand Down
8 changes: 3 additions & 5 deletions ext/intl/resourcebundle/resourcebundle_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,12 @@ static inline ResourceBundle_object *php_intl_resourcebundle_fetch_object(zend_o
#define RESOURCEBUNDLE_METHOD_INIT_VARS INTL_METHOD_INIT_VARS(ResourceBundle, rb)
#define RESOURCEBUNDLE_METHOD_FETCH_OBJECT_NO_CHECK INTL_METHOD_FETCH_OBJECT(INTL_RESOURCEBUNDLE, rb)
#define RESOURCEBUNDLE_METHOD_FETCH_OBJECT \
INTL_METHOD_FETCH_OBJECT(INTL_RESOURCEBUNDLE, rb); \
INTL_METHOD_FETCH_OBJECT(INTL_RESOURCEBUNDLE, rb); \
if (RESOURCEBUNDLE_OBJECT(rb) == NULL) { \
intl_errors_set(&rb->error, U_ILLEGAL_ARGUMENT_ERROR, \
"Found unconstructed ResourceBundle", 0); \
RETURN_FALSE; \
zend_throw_error(NULL, "Found unconstructed ResourceBundle"); \
RETURN_THROWS(); \
}


#define RESOURCEBUNDLE_OBJECT(rb) (rb)->me

void resourcebundle_register_class( void );
Expand Down
6 changes: 3 additions & 3 deletions ext/intl/spoofchecker/spoofchecker.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ public function isSuspicious(string $text, &$error = null) {}
/** @return bool */
public function areConfusable(string $s1, string $s2, &$error = null) {}

/** @return null|false */
/** @return void */
public function setAllowedLocales(string $locale_list) {}

/** @return null|false */
/** @return void */
public function setChecks(int $checks) {}

#if U_ICU_VERSION_MAJOR_NUM >= 58
/** @return null|false */
/** @return void */
public function setRestrictionLevel(int $level) {}
#endif
}
5 changes: 2 additions & 3 deletions ext/intl/spoofchecker/spoofchecker_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ extern zend_class_entry *Spoofchecker_ce_ptr;
#define SPOOFCHECKER_METHOD_FETCH_OBJECT \
SPOOFCHECKER_METHOD_FETCH_OBJECT_NO_CHECK; \
if (co->uspoof == NULL) { \
intl_errors_set(&co->err, U_ILLEGAL_ARGUMENT_ERROR, \
"Found unconstructed Spoofchecker", 0); \
RETURN_FALSE; \
zend_throw_error(NULL, "Found unconstructed Spoofchecker"); \
RETURN_THROWS(); \
}

// Macro to check return value of a ucol_* function call.
Expand Down
12 changes: 6 additions & 6 deletions ext/intl/tests/symfony_format_type_double_intl1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ $unit_test_args = unserialize('a:3:{i:0;O:15:"NumberFormatter":0:{}i:1;i:1;i:2;s
var_dump($unit_test_args);

// execute the code from #testFormatTypeDoubleIntl
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_DOUBLE);

echo "== didn't crash ==".PHP_EOL;

?>
try {
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_DOUBLE);
} catch (Error $exception) {
echo $exception->getMessage() . "\n";
}
--EXPECT--
array(3) {
[0]=>
Expand All @@ -27,4 +27,4 @@ array(3) {
[2]=>
string(1) "1"
}
== didn't crash ==
Found unconstructed NumberFormatter
12 changes: 6 additions & 6 deletions ext/intl/tests/symfony_format_type_double_intl2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ $unit_test_args = unserialize('a:3:{i:0;O:15:"NumberFormatter":0:{}i:1;d:1.10000
var_dump($unit_test_args);

// execute the code from #testFormatTypeDoubleIntl
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_DOUBLE);

echo "== didn't crash ==".PHP_EOL;

?>
try {
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_DOUBLE);
} catch (Error $exception) {
echo $exception->getMessage() . "\n";
}
--EXPECT--
array(3) {
[0]=>
Expand All @@ -27,4 +27,4 @@ array(3) {
[2]=>
string(3) "1.1"
}
== didn't crash ==
Found unconstructed NumberFormatter
12 changes: 6 additions & 6 deletions ext/intl/tests/symfony_format_type_double_intl3.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ $unit_test_args = unserialize('a:3:{i:0;O:15:"NumberFormatter":0:{}i:1;i:1;i:2;s
var_dump($unit_test_args);

// execute the code from #testFormatTypeDoubleIntl
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_DOUBLE);

echo "== didn't crash ==".PHP_EOL;

?>
try {
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_DOUBLE);
} catch (Error $exception) {
echo $exception->getMessage() . "\n";
}
--EXPECT--
array(3) {
[0]=>
Expand All @@ -27,4 +27,4 @@ array(3) {
[2]=>
string(7) "SFD1.00"
}
== didn't crash ==
Found unconstructed NumberFormatter
11 changes: 6 additions & 5 deletions ext/intl/tests/symfony_format_type_double_intl4.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ $unit_test_args = unserialize('a:3:{i:0;O:15:"NumberFormatter":0:{}i:1;d:1.10000
var_dump($unit_test_args);

// execute the code from #testFormatTypeDoubleIntl
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_DOUBLE);

echo "== didn't crash ==".PHP_EOL;

try {
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_DOUBLE);
} catch (Error $exception) {
echo $exception->getMessage() . "\n";
}
?>
--EXPECT--
array(3) {
Expand All @@ -27,4 +28,4 @@ array(3) {
[2]=>
string(7) "SFD1.10"
}
== didn't crash ==
Found unconstructed NumberFormatter
12 changes: 6 additions & 6 deletions ext/intl/tests/symfony_format_type_int32_intl1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ $unit_test_args = unserialize('a:3:{i:0;O:15:"NumberFormatter":0:{}i:1;i:1;i:2;s
var_dump($unit_test_args);

// execute the code from #testFormatTypeInt32Intl
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT32);

echo "== didn't crash ==".PHP_EOL;

?>
try {
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT32);
} catch (Error $exception) {
echo $exception->getMessage() . "\n";
}
--EXPECT--
array(3) {
[0]=>
Expand All @@ -46,4 +46,4 @@ array(3) {
[2]=>
string(1) "1"
}
== didn't crash ==
Found unconstructed NumberFormatter
12 changes: 6 additions & 6 deletions ext/intl/tests/symfony_format_type_int32_intl2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ $unit_test_args = unserialize('a:3:{i:0;O:15:"NumberFormatter":0:{}i:1;d:1.10000
var_dump($unit_test_args);

// execute the code from #testFormatTypeInt32Intl
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT32);

echo "== didn't crash ==".PHP_EOL;

?>
try {
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT32);
} catch (Error $exception) {
echo $exception->getMessage() . "\n";
}
--EXPECT--
array(3) {
[0]=>
Expand All @@ -30,4 +30,4 @@ array(3) {
[2]=>
string(1) "1"
}
== didn't crash ==
Found unconstructed NumberFormatter
12 changes: 6 additions & 6 deletions ext/intl/tests/symfony_format_type_int32_intl3.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ $unit_test_args = unserialize('a:4:{i:0;O:15:"NumberFormatter":0:{}i:1;d:2147483
var_dump($unit_test_args);

// execute the code from #testFormatTypeInt32Intl
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT32);

echo "== didn't crash ==".PHP_EOL;

?>
try {
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT32);
} catch (Error $exception) {
echo $exception->getMessage() . "\n";
}
--EXPECT--
array(4) {
[0]=>
Expand All @@ -29,4 +29,4 @@ array(4) {
[3]=>
string(83) "->format() TYPE_INT32 formats inconsistently an integer if out of the 32 bit range."
}
== didn't crash ==
Found unconstructed NumberFormatter
12 changes: 6 additions & 6 deletions ext/intl/tests/symfony_format_type_int32_intl4.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ $unit_test_args = unserialize('a:3:{i:0;O:15:"NumberFormatter":0:{}i:1;i:1;i:2;s
var_dump($unit_test_args);

// execute the code from #testFormatTypeInt32Intl
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT32);

echo "== didn't crash ==".PHP_EOL;

?>
try {
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT32);
} catch (Error $exception) {
echo $exception->getMessage() . "\n";
}
--EXPECT--
array(3) {
[0]=>
Expand All @@ -27,4 +27,4 @@ array(3) {
[2]=>
string(7) "SFD1.00"
}
== didn't crash ==
Found unconstructed NumberFormatter
12 changes: 6 additions & 6 deletions ext/intl/tests/symfony_format_type_int32_intl5.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ $unit_test_args = unserialize('a:3:{i:0;O:15:"NumberFormatter":0:{}i:1;d:1.10000
var_dump($unit_test_args);

// execute the code from #testFormatTypeInt32Intl
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT32);

echo "== didn't crash ==".PHP_EOL;

?>
try {
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT32);
} catch (Error $exception) {
echo $exception->getMessage() . "\n";
}
--EXPECT--
array(3) {
[0]=>
Expand All @@ -27,4 +27,4 @@ array(3) {
[2]=>
string(7) "SFD1.00"
}
== didn't crash ==
Found unconstructed NumberFormatter
12 changes: 6 additions & 6 deletions ext/intl/tests/symfony_format_type_int32_intl6.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ $unit_test_args = unserialize('a:4:{i:0;O:15:"NumberFormatter":0:{}i:1;d:2147483
var_dump($unit_test_args);

// execute the code from #testFormatTypeInt32Intl
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT32);

echo "== didn't crash ==".PHP_EOL;

?>
try {
$unit_test_args[0]->format($unit_test_args[1], \NumberFormatter::TYPE_INT32);
} catch (Error $exception) {
echo $exception->getMessage() . "\n";
}
--EXPECT--
array(4) {
[0]=>
Expand All @@ -29,4 +29,4 @@ array(4) {
[3]=>
string(83) "->format() TYPE_INT32 formats inconsistently an integer if out of the 32 bit range."
}
== didn't crash ==
Found unconstructed NumberFormatter
Loading