-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
INIT_CLASS_ENTRY should use strlen() to determine class name length #10217
Comments
On current master (PHP-8.2) |
I don't understand why this would be a bug. Are you writing a PHP extension? If so, you can use |
I made several PHP extensions. Due to platform restrictions, these are all required to compile on multiple versions of PHP (5.4->8.0) . As the internals changed a lot over the years, I created several wrappers so that I didn't need to repeat large blocks of code doing the same just ever so slightly different. One of these wrappers is responsible for registering classes and their corresponding methods. Among other things, this wrapper calls However, since template<size_t name_len>
void register_class(const char (&name)[name_len], const zend_function_entry * methods) I could call In any case, I only encountered this problem until very late in the development process on 32-bit platforms because my class names just happened to be 7 characters long. At first I thought it was the usual 32/64-bit bug but a couple hours debugging later I found this gem, resulting in the expected "why???" response. |
Ugh, that's a tough requirement. Anyhow, I think we can change |
I think for stuff like this which may be used by extensions it makes sense to proceed with those changes compared to changing all possible instances within bundled extensions |
It was not fun, no. We all know sizeof() is intended to get the size of something and strlen() is intended to get the length of a string. Most compilers nowadays will substitute strlen() calls with a constant anyway so its really not optimizing anything. I haven't gone too deep into it but historically there have been many attempts to limit/reduce copies of strings (interned strings, The only real danger would be someone passing in a heap- or stack-allocated string, the string argument not being copied and something internally trying to dereference the original (now invalid) string pointer. Would be really easy to test, though. By the way most/all of the non-ex add_property_* macros take sizeof(name) too. Or used to, argh... so many versions I had to deal with I can't remember! |
@dbuteyn, maybe you want to provide a respective PR? |
|
Yeah, I don't think |
Description
This works:
This does not:
Because
INIT_OVERLOADED_CLASS_ENTRY
usessizeof()
to determine class_name_len:PHP Version
All
Operating System
All
The text was updated successfully, but these errors were encountered: