From 6a80918ccc1bd438d63efafafc9a25d6664586a6 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Wed, 1 Jan 2025 16:57:57 +0000 Subject: [PATCH] Fix GH-17317: ResourceBundle crash on undefined iterator key. --- .../resourcebundle/resourcebundle_iterator.c | 7 ++- ext/intl/tests/gh17317.phpt | 48 +++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 ext/intl/tests/gh17317.phpt diff --git a/ext/intl/resourcebundle/resourcebundle_iterator.c b/ext/intl/resourcebundle/resourcebundle_iterator.c index 9ec97f64f51d4..e5e5d687c2d97 100644 --- a/ext/intl/resourcebundle/resourcebundle_iterator.c +++ b/ext/intl/resourcebundle/resourcebundle_iterator.c @@ -105,7 +105,12 @@ static void resourcebundle_iterator_key( zend_object_iterator *iter, zval *key ) } if (iterator->is_table) { - ZVAL_STRING(key, iterator->currentkey); + if (EXPECTED(iterator->currentkey)) { + ZVAL_STRING(key, iterator->currentkey); + } else { + ZVAL_NULL(key); + ZVAL_NULL(&iterator->current); + } } else { ZVAL_LONG(key, iterator->i); } diff --git a/ext/intl/tests/gh17317.phpt b/ext/intl/tests/gh17317.phpt new file mode 100644 index 0000000000000..ee0aab570541b --- /dev/null +++ b/ext/intl/tests/gh17317.phpt @@ -0,0 +1,48 @@ +--TEST-- +GH-17319 (ResourceBundle iterator crash on NULL key) +--EXTENSIONS-- +intl +--CREDITS-- +KidFlo +--FILE-- +get('calendar')->get('buddhist') as $key => $value) { + echo "KEY: "; var_dump($key); + echo "VALUE: "; var_dump($value); +} +?> +--EXPECT-- +KEY: string(15) "AmPmMarkersAbbr" +VALUE: object(ResourceBundle)#3 (0) { +} +KEY: string(15) "AmPmMarkersAbbr" +VALUE: object(ResourceBundle)#4 (0) { +} +KEY: string(16) "DateTimePatterns" +VALUE: object(ResourceBundle)#3 (0) { +} +KEY: NULL +VALUE: NULL +KEY: NULL +VALUE: NULL +KEY: string(11) "appendItems" +VALUE: object(ResourceBundle)#3 (0) { +} +KEY: string(16) "availableFormats" +VALUE: object(ResourceBundle)#4 (0) { +} +KEY: string(8) "dayNames" +VALUE: object(ResourceBundle)#3 (0) { +} +KEY: string(4) "eras" +VALUE: object(ResourceBundle)#4 (0) { +} +KEY: string(15) "intervalFormats" +VALUE: object(ResourceBundle)#3 (0) { +} +KEY: string(10) "monthNames" +VALUE: object(ResourceBundle)#4 (0) { +} +KEY: string(8) "quarters" +VALUE: object(ResourceBundle)#3 (0) { +}