-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-106263: Fix segfault in signaldict_repr
#106270
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
Conversation
Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com>
Modules/_decimal/_decimal.c
Outdated
static int | ||
signaldict_init(PyObject *self, PyObject *args UNUSED, PyObject *kwds UNUSED) | ||
{ | ||
SdFlagAddr(self) = NULL; | ||
SdFlagAddr(self) = &dflt_ctx.status; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They will all share the same flags.
Will users start to misuse this construction method, then found in surprise that its flags being changed without notice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer forbidding this than silently allowing this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! It seems that it is not easy to forbid instantiation directly, because decimal.Context()
depends on the signaldict
instance. If you have a good idea, please let me know :) Or let's wait for advice from other professionals~
At first I considered two solutions to fix this:
Assuming that there is a class with parameterless constructor, we use this constructor to create an instance of the class, then call the method of the class, and then the program crashes. It sounds weird, even though we don't want users to call this constructor directly. IMO, it makes sense to properly initialize instance attributes in a parameterless constructor. So I prefer solution 2 for now, it's simple and works. Please correct me if I am wrong :) |
How about this? Disallowing |
I got you. But this seems to limit users from changing the value of cpython/Modules/_decimal/_decimal.c Lines 1275 to 1283 in 04dfc6f
That's why we hate global variable. What if we choose option 1? @sunmy2019 We need to add pointer checker for all methods of |
This comment was marked as outdated.
This comment was marked as outdated.
I got you now. I didn't look into it closely.
This is what I previously preferred. |
@erlend-aasland I updated this PR, would you mind to review this :) |
Thanks, Kumar and Charlie! Should this be backported? |
I think it should. |
Yes, it should. This backport does not bring any side effects. If there are conflicts, I can manually backport them. :) |
Thanks @CharlieZhao95 for the PR, and @kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11. |
Thanks @CharlieZhao95 for the PR, and @kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12. |
Sorry, @CharlieZhao95 and @kumaraditya303, I could not cleanly backport this to |
Sorry, @CharlieZhao95 and @kumaraditya303, I could not cleanly backport this to |
…le (python#106270) Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com> (cherry picked from commit 3979150)
…le (python#106270) Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com> (cherry picked from commit 3979150)
GH-107490 is a backport of this pull request to the 3.11 branch. |
GH-107491 is a backport of this pull request to the 3.12 branch. |
Fix potential crash risks in
signaldict
object.decimal.SignalDictMixin
type #106263