-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
FFICasterTest::testCastNonTrailingCharPointer() breaks PHPs community build #47668
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
/cc @SerafimArts any advice here? could anyone please send a fix? |
@nicolas-grekas why was this closed ? I can't find any related code change |
Probably by accident. I sent a different fix for the FFI test. 🙂 |
Oops :) |
What would be the preferred solution here? To fully remove |
Yes this is true. In some cases, string rendering can fit into "foreign memory" and cause a SIGSEG/etc errors. This is a rather rare case, but I have already encountered it. However, using
It is impossible to solve this problem in a simple way, so I offer two options:
Tests for the behavior of displaying such values will also have to be removed. P.S. In theory, we can check that a string is safe by calling smth like |
Yep. It just checks the behavior when the string does not end with "\0" and the dumper gets into non-string memory. That is, this "mistake" was deliberately made there with the hope that a piece of |
@SerafimArts Thanks for your response!
True. However in this case, at least the pointer is pointing to invalid memory. In the case of
Since PHP runs in user space there is not really a concern of reading the memory of another process (all memory addresses are local, only the kernel can refer to global addresses) but rather accessing "unmapped" addresses which don't necessarily have to be far away from the address you're reading. In most cases you'll probably be "lucky" and read data from the same page or PHP will have already allocated the page next to it. However:
Unfortunately, I don't think there's a good way to solve that. I doubt most people would expect that |
Yes, that's why I added a comment there that this test might break =( @nicolas-grekas Are you satisfied with the PR of removing tests for displaying string vars ( Or reading the environment vars inside the FFICaster is not the right way to fine-tune it? |
In this case, the |
Printing the first char should be fine memory wise. Thank you! |
But the functionality with displaying full strings, although not always safe, is convenient. I don't want to get rid of it completely. In general, if @nicolas-grekas approves of such an option (or suggests a more symfony-way), then I would prefer to leave it with the ability to somehow turn it on leaving the default behavior with displaying only the first character. |
If I can disable it in the PHP community build I'm happy. 🙂 Of course, I can also just disable the entire test but I thought I'd let you know that this triggered an error in our build. |
We could add Does var_dump also crash on the same data? print_r? Because if not, we could leverage them? The filter can be given when calling AbstractCloner::cloneVar(). This is not readdly comfigurable from the outside yet but #48667 might be a nice way forward for this. |
Yes! This is pretty much what I've done in our CI for now.
The problem is that the length of the string is unknown so we can't safely construct a PHP string either. |
As I understand that it makes sense to wait for the application of the PR #48667 and continue to use this functionality (of subj PR) to control the output of unsafe |
Hey, thanks for your report! |
We ignored this test on our side, so feel free to close this issue if you don't want to fix it. |
Hey, thanks for your report! |
Friendly reminder that this issue exists. If I don't hear anything I'll close this. |
Hey, I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen! |
Uh oh!
There was an error while loading. Please reload this page.
Symfony version(s) affected
6.2
Description
symfony/src/Symfony/Component/VarDumper/Tests/Caster/FFICasterTest.php
Lines 194 to 205 in e6d6bed
See https://github.com/iluuu1994/php-src/actions/runs/3106907448/jobs/5034370701.
How to reproduce
Possible Solution
The
NUL
byte should be part of the array, otherwise this is writing to unrelated memory. The memory sanitizer complains about$pointer[$actualLength] = "\x01";
, because the assignment happens to unowned memory. The string should be allocated as$string = \FFI::new('char['.($actualLength + 1).']');
to allow this, although that likely defeats the purpose of the test as there is probably anotherNUL
byte right after. Printingchar*
is likely unsafe because user allocated C strings are not guaranteed to beNUL
-terminated. Just reading from the unowned memory is also unsafe and can cause SEGFAULTs.Additional Context
No response
The text was updated successfully, but these errors were encountered: