-
Notifications
You must be signed in to change notification settings - Fork 7.8k
SplFileObject::fputcsv()
via reflection causes segfault
#16217
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
Comments
ubsan main/streams/streams.c:1297:14: runtime error: member access within null pointer of type 'php_stream' (aka 'struct _php_stream') |
Honestly, I'd be surprised if there weren't many other cases of |
I think we should do our best to avoid segfaults and undefined behavior. Instead of doing is_initialized checks in all methods, maybe it would be sufficient to explicitly disallow php-src/ext/reflection/php_reflection.c Lines 5144 to 5148 in 2501cad
Maybe we could introduce another flag (I guess we're running out of these, though); or maybe we can disallow the reflection method for all internal classes which are not serializable. |
I don't object to that, although I'm not sure how much it will help, as we don't use Strictly speaking, it might not be sound to call This was later changed to allowing internal classes with non-final constructors. I'm guessing the rationale is that a child class might override |
Found the earlier discussion: #11416 (comment) I agree that we should do our best to avoid segfaults. Most internal classes need to cast php-src/ext/reflection/php_reflection.c Lines 113 to 127 in 2501cad
php-src/ext/spl/spl_directory.c Lines 664 to 669 in 2501cad
That's why calling Most of these cases should be discovered by this test. Maybe we can extend it to also call the methods with Unfortunately, denying |
That sounds like a risky test. 😅 Edit: Oh, we're already calling functions. It seems we have already thrown caution to the wind 😄 |
The problem with arginfo_zpp_mismatch.phpt is that it only checks already loaded classes; this is why it does not segfault when |
May I propose an idea? Currently,
It might be better to make this object handler optional, and if this is NULL just ban Don't have an idea how to address the internal classes that have a constructor which must be called. But tbf what is even the point of using Also note that PDO may also instantiate a class without calling the constructor. |
Unfortunately this doesn't solve the issue for classes that have a constructor and are supposed to be instantiated with |
For the record, I tried running (for the built in classes and extensions enabled by default, i.e. only from I'm planning to do this for all of the bundled extensions at some point soon though |
There is already Zend/tests/arginfo_zpp_mismatch.phpt and friends, which instantiate all classes via
See PR #16251 (shot myself in the foot when removing the |
Another one: #16763 |
Description
The following code:
Resulted in this output:
But I expected this output instead:
See https://3v4l.org/uqjqf for confirmation.
Valgrind locally for 8.4 reports
PHP Version
PHP 8.2+
Operating System
No response
The text was updated successfully, but these errors were encountered: