Skip to content

streams: Fix php_stream_from_{res|zval}_no_verify() APIs actually throwing TypeErrors #18079

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

Girgias
Copy link
Member

@Girgias Girgias commented Mar 15, 2025

If we pass a string as the resource_type_name parameter instead of NULL then a TypeError is emitted.

@Girgias Girgias force-pushed the stream-no-verify-fix branch from f645513 to e992ebb Compare March 15, 2025 22:09
@Girgias Girgias marked this pull request as ready for review March 15, 2025 23:00
@Girgias Girgias requested review from bukka and nielsdos as code owners March 15, 2025 23:00
@@ -771,11 +771,17 @@ static xmlParserInputPtr php_libxml_external_entity_loader(const char *URL,
} else if (Z_TYPE(retval) == IS_RESOURCE) {
php_stream *stream;
php_stream_from_zval_no_verify(stream, &retval);
if (stream == NULL) {
if (UNEXPECTED(stream == NULL)) {
Copy link
Member

Choose a reason for hiding this comment

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

This code fragment just looks like a completely different fix (for stable branches as well)?

@@ -282,8 +282,8 @@ END_EXTERN_C()
return; \
} \
} while (0)
#define php_stream_from_res_no_verify(xstr, pzval) (xstr) = (php_stream*)zend_fetch_resource2((res), "stream", php_file_le_stream(), php_file_le_pstream())
#define php_stream_from_zval_no_verify(xstr, pzval) (xstr) = (php_stream*)zend_fetch_resource2_ex((pzval), "stream", php_file_le_stream(), php_file_le_pstream())
#define php_stream_from_res_no_verify(xstr, pzval) (xstr) = (php_stream*)zend_fetch_resource2((res), NULL, php_file_le_stream(), php_file_le_pstream())
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 understand the motivation, the no_verify just means that the macro won't return, so it's just an unclear name.
Also this behaviour change does not seem worth it for extensions?

Copy link
Member Author

Choose a reason for hiding this comment

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

The motivation is to have an API that extension can rely on to get a php_stream (mainly from a zval) to ease the migration from resource to objects. And we have a bunch of case which use zend_fetch_resource2 with NULL so they can handle the errors themselves.

I guess I'll just add a new macro/inline function

Copy link
Member

Choose a reason for hiding this comment

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

I would prefer not doing those incremental changes. Once there is such migration, users will need to handle it anyway.

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.

4 participants