Skip to content

Commit

Permalink
Fix phpGH-17317: ResourceBundle crash on undefined iterator key.
Browse files Browse the repository at this point in the history
  • Loading branch information
devnexen committed Jan 1, 2025
1 parent 717b75c commit 6a80918
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ext/intl/resourcebundle/resourcebundle_iterator.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
48 changes: 48 additions & 0 deletions ext/intl/tests/gh17317.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
--TEST--
GH-17319 (ResourceBundle iterator crash on NULL key)
--EXTENSIONS--
intl
--CREDITS--
KidFlo
--FILE--
<?php
foreach ((new ResourceBundle('', NULL))->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) {
}

0 comments on commit 6a80918

Please sign in to comment.