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

Conversation

devnexen
Copy link
Member

@devnexen devnexen commented Jan 1, 2025

No description provided.

@devnexen devnexen marked this pull request as ready for review January 1, 2025 18:10
@devnexen devnexen linked an issue Jan 1, 2025 that may be closed by this pull request
Comment on lines +5 to +6
--CREDITS--
KidFlo
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. :)

Comment on lines 108 to 113
if (EXPECTED(iterator->currentkey)) {
ZVAL_STRING(key, iterator->currentkey);
} else {
ZVAL_NULL(key);
}
Copy link
Member

Choose a reason for hiding this comment

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

That doesn't look quite right, since the corresponding value would be Z_ISUNDEF and we (usually) don't expose these.

I have no idea, though, what to do instead when resourcebundle_iterator_read() fails with U_MISSING_RESOURCE_ERROR. Hmm, since (new ResourceBundle('', NULL))->get('calendar')->get('buddhist')->get(3) returns null, maybe we should also set the value to null.

ZVAL_STRING(key, iterator->currentkey);
} else {
ZVAL_NULL(key);
ZVAL_NULL(&iterator->current);
Copy link
Member

Choose a reason for hiding this comment

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

Setting this here wouldn't have any effect when users traverse over the values only. Changing it in resourcebundle_iterator_read() would require more changes (elsewhere there are checks for Z_ISUNDEF(iterator->current)), and we might break existing semantics. Maybe resourcebundle_iterator_current() would need to return null, but we don't have a zval there. :/

And I wonder about:

$rb = (new ResourceBundle('', NULL))->get('calendar')->get('buddhist');
var_dump($rb->get(3));
var_dump($rb->getErrorMessage());
foreach ($rb as $key => $value) {
    var_dump($key);
    var_dump($rb->getErrorMessage());
}

That reports Cannot load resource element 3: U_MISSING_RESOURCE_ERROR after the ::get() call, but U_ZERO_ERROR when traversing.

Given that value only traversal so far "worked" but returned undef values (and apparently nobody complained), maybe as bugfix we should just set the key to undef (instead of null), and try a proper fix in the master branch only.

Copy link
Member Author

Choose a reason for hiding this comment

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

Given that value only traversal so far "worked" but returned undef values (and apparently nobody complained), maybe as bugfix we should just set the key to undef (instead of null), and try a proper fix in the master branch only.

I wanted to this at first but it seemed to me the more spread fashion was to set to NULL.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, exposing undef values is certainly uncommon, while having null as iterator key is not.

Copy link
Member Author

Choose a reason for hiding this comment

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

it seems to cause issue with JIT.

Copy link
Member

Choose a reason for hiding this comment

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

Undef values should never get exposed to userland.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, but how to solve that for the values (they are already undef)?

Copy link
Member

Choose a reason for hiding this comment

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

I will take a look in this issue in a few hours. In general undef should be transformed into null but this is weird in this case. Possibly the undef values should be skipped, which is conceptually similar to arrays. But anyway, I will first try to understand how and why sometime later today.

@devnexen devnexen marked this pull request as draft January 1, 2025 23:28
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Iterating on ResourceBundle (using keys) causes segmentation fault
3 participants