-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
undefined behavior: tstate->datastack_top == NULL #96569
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 @markshannon It looks like this happens at the very first call to PyEval_EvalCode, when executing It goes: |
In any case here's my bisecting log:
(Ignore the |
It looks like this is happening in the 3.11 branch @pablogsal |
I'm suspicious of 45e62a2, where |
One option would be to never let datastack_top be NULL, but that could interfere with the efforts at 77195cd to be compatible with greenlet and other frame-swapping extensions. So by my shallow understanding, the easiest solution is probably just to check for NULL when pushing frames. |
Given that:
I think we should go back to ensuring that In the short term, we could add the @pablogsal thoughts? |
@markshannon The latest version of greenlet is compatible with 3.11 https://pypi.org/project/greenlet/#files |
As mentioned previously, greenlet has been released being compatible with 3.11 so whatever we do we should try to not break it. What consequences ensuring that I agree that for 3.11 (and given that the last RC release is today) we should add a null check as long as we understand the consequences of that because we really don't want to learn about side effects later. |
Is greenlet compatible with 3.11? There has been no work on it since March |
You're looking at the master branch — there were commits eleven days ago on the 1.1 branch https://github.com/python-greenlet/greenlet/tree/maint/1.1 And there was a new release on August 25, adding compatibility with 3.11: https://pypi.org/project/greenlet/ |
|
What potential failures are we talking about? I don't feel comfortable making a patch that we can regret later because we discover that it fails in a bunch of unknown scenarios |
What patch? Ensuring that |
Adding
|
Adding Making sure that |
I understand that, that's what I am saying that I don't feel comfortable just adding |
The The comparison There isn't much we can do about that, apart from better static analysis. |
Ok I see. How does making sure that datastack_top is never NULL break greenlets? |
More specifically, in this case the arithmetic is already undefined. Null + anything is undefined. You don't even need to use the pointer in any way afterwards or compare it etc. Undefined behaviour also 'travels backwards in time'. Ie it removes any obligation on the compiler for the entire execution, not just for what happens after the UB occurs. (I haven't seen this instance here cause any problems in practice, but I also didn't look for problems. I stopped at getting a reproduction, and only looked into the causes a bit.) So the potential problem is not so much that your comparison will give an unexpected result, but that an optimisting compiler will remove the entire branch that leads up to the UB (because compilers like to treat UB by just pretending the circumstances in which it occurs can never happen, and this lets them remove code, and thus win speed benchmarks.) |
Greenlets sets |
How confident are you adding |
Fairly confident |
Oh, that's surpising. With my change, co-authored by Miro Hrončok (@hroncok), greenlet only saves/restores datastack_top value: python-greenlet/greenlet@31ccde2 |
Ok, let's go with the NULL check then for 3.11 unless there is a better alternative |
A new greenlet has a |
Co-authored-by: Michael Droettboom <[email protected]>
Does this still need to stay open? @pablogsal @markshannon |
I think we can close this, because we have merged fixes for both main (a while ago) and 3.11 (more recently). I am closing this issue. But please feel free to reopen, if necessary. |
I was chasing down some C trouble in code I had been experimenting. I used all the debug options I could find:
For sanity checking, I ran this on current main. I got:
For a minimal reproducible example, have a look at my example PR that adds this check and fails to build:
Error messages
Enter any relevant error message caused by the crash, including a core dump if there is one.
I already pasted the error message I get from the sanitizers above. Here's the error message I get from my assertion instead (and building with just sequential
make
):Your environment
I tested this on Archlinux against latest
main
. You can also see it in action on the failed test run for my PR on github.The text was updated successfully, but these errors were encountered: