Skip to content

Commit 5ce2e26

Browse files
committed
gh-162777: Check exact Decimal operands before int64 fast path
1 parent dd278b6 commit 5ce2e26

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

‎Modules/_decimal/_decimal.c‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4535,13 +4535,27 @@ nm_##MPDFUNC(PyObject *self, PyObject *other) \
45354535
\
45364536
decimal_state *state = find_state_left_or_right(self, other); \
45374537
CURRENT_CONTEXT(state, context) ; \
4538+
if (PyDec_CheckExact(state, self) && \
4539+
PyDec_CheckExact(state, other)) { \
4540+
if ((result = dec_alloc(state)) == NULL) { \
4541+
return NULL; \
4542+
} \
4543+
MPDFUNC(MPD(result), MPD(self), MPD(other), \
4544+
CTX(context), &status); \
4545+
if (dec_addstatus(context, status)) { \
4546+
Py_DECREF(result); \
4547+
return NULL; \
4548+
} \
4549+
return result; \
4550+
} \
45384551
int reflected = PyLong_CheckExact(self); \
45394552
if (reflected || PyLong_CheckExact(other)) { \
45404553
PyObject *integer = reflected ? self : other; \
45414554
int overflow; \
45424555
long long value = \
45434556
PyLong_AsLongLongAndOverflow(integer, &overflow); \
45444557
if (!overflow) { \
4558+
Py_BUILD_ASSERT(sizeof(value) == sizeof(int64_t)); \
45454559
return dec_binop_int64(state, context, MPDFUNC, \
45464560
reflected ? other : self, \
45474561
value, reflected); \

0 commit comments

Comments
 (0)