-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Do not copy the normalized URI when cloning RFC 3986 URIs - alternative approach #19744
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -990,7 +990,13 @@ zend_object *uri_clone_obj_handler(zend_object *object) | |
|
||
new_uri_object->internal.parser = internal_uri->parser; | ||
|
||
void *uri = internal_uri->parser->clone_uri(internal_uri->uri); | ||
zend_execute_data *execute_data = EG(current_execute_data); | ||
bool is_clone_op = execute_data != NULL && | ||
execute_data->func && | ||
ZEND_USER_CODE(execute_data->func->type) && | ||
execute_data->opline != NULL && | ||
execute_data->opline->opcode == ZEND_CLONE; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please no, I object against these kinds of hacks. This might also not work well with the clone-as-function feature. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. :( alright There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there any other solution you can see that achieves similar result? The only thing I can is to set a global variable before cloning that the RFC 3986 implementation could check. But I guess this is also going to be considered hacky :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would assume that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that is a reasonable assumption, however Tim has just changed the code of the withers to call the clone obj handler instead of directly calling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is still unclear to me, why we try to add this amount of complexity to the C code, when my previous suggestion of "just don't clone the normalized URI, because it's very likely to be invalidated" would be obviously correct. As part of my cleanup and review of ext/uri, I've fixed more one one case of memory unsafety. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're doing too much premature optimization here. Go for the simple solution of Tim where we just don't copy the normalized URI. It's going to be much easier and less error-prone. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The change to properly copy normalized URIs when needed didn't seem complex to me: we could go back using Yes, this improves the situation for only a small minority of use-cases, but for them, it's a huge improvement not to have to reparse the whole URI. Of course, real world benchmarks won't reveal this, unless I deliberately start cloning URIs like crazy for whatever reason. In my opinion, this warrants the extra care. Not missing this opportunity seems more vital for me than optimizing other smaller details like converting With all that said, if you both agree that we shouldn't take care of this usecase, then I'll accept and respect your decision, and close this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
FWIW: I also agree with that. For me it's needless mental load that all these variants exist and just always use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah and what I also wanted to add: One issue I'm having here is that this would be adding another parameter to the API that only matters for one of the implementations, similarly to the |
||
void *uri = internal_uri->parser->clone_uri(internal_uri->uri, is_clone_op == false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This way the extra check affects all URI parsers - so the above check could be directly added to the clone_uri handler of RFC 3986... 🤔 |
||
ZEND_ASSERT(uri != NULL); | ||
|
||
new_uri_object->internal.uri = uri; | ||
|