Skip to content

PyDecContextObject and PyDecObject in decimal module are missing PyObject_GC_Track #107994

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

Open
2 tasks done
CharlieZhao95 opened this issue Aug 16, 2023 · 1 comment
Open
2 tasks done
Labels
extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error

Comments

@CharlieZhao95
Copy link
Contributor

Checklist

  • I am confident this is a bug in CPython, not a bug in a third-party project
  • I have searched the CPython issue tracker,
    and am confident this bug has not been reported before

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Output from running 'python -VV' on the command line:

No response

A clear and concise description of the bug:

There are two objects(PyDecContextObject and PyDecObject) using PyObject_GC_New in the decimal module, but PyObject_GC_Track is not added to their constructors.

PyDecContextObject:

static PyObject *
context_new(PyTypeObject *type, PyObject *args UNUSED, PyObject *kwds UNUSED)
{
PyDecContextObject *self = NULL;
mpd_context_t *ctx;
decimal_state *state = get_module_state_by_def(type);
if (type == state->PyDecContext_Type) {
self = PyObject_GC_New(PyDecContextObject, state->PyDecContext_Type);
}
else {
self = (PyDecContextObject *)type->tp_alloc(type, 0);
}
if (self == NULL) {
return NULL;
}
self->traps = PyObject_CallObject((PyObject *)state->PyDecSignalDict_Type, NULL);
if (self->traps == NULL) {
self->flags = NULL;
Py_DECREF(self);
return NULL;
}
self->flags = PyObject_CallObject((PyObject *)state->PyDecSignalDict_Type, NULL);
if (self->flags == NULL) {
Py_DECREF(self);
return NULL;
}
ctx = CTX(self);
if (state->default_context_template) {
*ctx = *CTX(state->default_context_template);
}
else {
*ctx = dflt_ctx;
}
SdFlagAddr(self->traps) = &ctx->traps;
SdFlagAddr(self->flags) = &ctx->status;
CtxCaps(self) = 1;
self->tstate = NULL;
return (PyObject *)self;
}

PyDecObject:

static PyObject *
PyDecType_New(PyTypeObject *type)
{
PyDecObject *dec;
decimal_state *state = get_module_state_by_def(type);
if (type == state->PyDec_Type) {
dec = PyObject_GC_New(PyDecObject, state->PyDec_Type);
}
else {
dec = (PyDecObject *)type->tp_alloc(type, 0);
}
if (dec == NULL) {
return NULL;
}
dec->hash = -1;
MPD(dec)->flags = MPD_STATIC|MPD_STATIC_DATA;
MPD(dec)->exp = 0;
MPD(dec)->digits = 0;
MPD(dec)->len = 0;
MPD(dec)->alloc = _Py_DEC_MINALLOC;
MPD(dec)->data = dec->data;
return (PyObject *)dec;
}

@CharlieZhao95 CharlieZhao95 added the type-bug An unexpected behavior, bug, or error label Aug 16, 2023
@CharlieZhao95
Copy link
Contributor Author

Another problem is that when I tried to fix them, I added this code: CharlieZhao95@05cf606.

But there is a segfault when building, which seems to be a buff overflow error, what's wrong here?

Checked 106 modules (31 built-in, 74 shared, 1 n/a on linux-x86_64, 0 disabled, 0 missing, 0 failed on import)
Debug memory block at address p=0x7fcf053f5220: API ''
    5786913340382969856 bytes originally requested
    The 7 pad bytes at p-7 are not all FORBIDDENBYTE (0xfd):
        at p-7: 0xdd *** OUCH
        at p-6: 0xdd *** OUCH
        at p-5: 0xdd *** OUCH
        at p-4: 0xdd *** OUCH
        at p-3: 0xdd *** OUCH
        at p-2: 0xdd *** OUCH
        at p-1: 0xdd *** OUCH
    Because memory is corrupted at the start, the count of bytes requested
       may be bogus, and checking the trailing pad bytes may segfault.
    The 8 pad bytes at tail=0x504fbed4d4be5220 are Segmentation fault (core dumped)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants