Skip to content

Fix GH-17317: ResourceBundle crash on undefined iterator key. #17318

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
wants to merge 2 commits into from
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
6 changes: 5 additions & 1 deletion ext/intl/resourcebundle/resourcebundle_iterator.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ 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_UNDEF(key);
}
} else {
ZVAL_LONG(key, iterator->i);
}
Expand Down
56 changes: 56 additions & 0 deletions ext/intl/tests/gh17317.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
--TEST--
GH-17319 (ResourceBundle iterator crash on NULL key)
--EXTENSIONS--
intl
--CREDITS--
KidFlo
Comment on lines +5 to +6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should add a CREDIT section to new tests; see also https://qa.php.net/phpt_details.php#credits_section.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree; I often add CREDITS section. Co-authored-by doesn't allow fine-grained tracking of what a person did, so that's a downgrade in comparison to the CREDITS section.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we should probably change the description accordingly. :)

--FILE--
<?php
foreach ((new ResourceBundle('', NULL))->get('calendar')->get('buddhist') as $key => $value) {
echo "KEY: "; var_dump($key);
echo "VALUE: "; var_dump($value);
}
?>
--EXPECT--
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use --EXPECTF-- here to be able to use placeholders for the specifc filenames (and line numbers) of the warnings below.

And maybe the test is overspecified; I have no idea how likely it is that the details of this resource bundle will change in ICU versions.

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:
Warning: Undefined variable $key in /home/dcarlier/Contribs/php-src/ext/intl/tests/gh17317.php on line 3
NULL
VALUE:
Warning: Undefined variable $value in /home/dcarlier/Contribs/php-src/ext/intl/tests/gh17317.php on line 4
NULL
KEY:
Warning: Undefined variable $key in /home/dcarlier/Contribs/php-src/ext/intl/tests/gh17317.php on line 3
NULL
VALUE:
Warning: Undefined variable $value in /home/dcarlier/Contribs/php-src/ext/intl/tests/gh17317.php on line 4
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) {
}
Loading