Skip to content

fix: check return code in unpack_callback_int64#665

Open
KowalskiThomas wants to merge 1 commit intomsgpack:mainfrom
KowalskiThomas:kowalski/fix-check-return-code-in-unpack_callback_int64
Open

fix: check return code in unpack_callback_int64#665
KowalskiThomas wants to merge 1 commit intomsgpack:mainfrom
KowalskiThomas:kowalski/fix-check-return-code-in-unpack_callback_int64

Conversation

@KowalskiThomas
Copy link
Copy Markdown

This simply adds a null pointer check after calling PyLong_FromLongLong / PyLong_FromLong like other similar functions do it (example here).

@KowalskiThomas KowalskiThomas marked this pull request as ready for review April 19, 2026 12:45
Comment thread msgpack/unpack.h
if (d > LONG_MAX) {
p = PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)d);
} else {
p = PyLong_FromLong((long)d);
Copy link
Copy Markdown
Contributor

@ThomasWaldmann ThomasWaldmann Apr 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be PyLong_FromUnsignedLong((unsigned long)d)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both are correct. Since we checked d <= LONG_MAX, (long)d is guaranteed to fit in a signed long.
But p = PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG)d) without d > LONG_MAX check would be better.

Comment thread msgpack/unpack.h
static inline int unpack_callback_int64(unpack_user* u, int64_t d, msgpack_unpack_object* o)
{
PyObject *p;
if (d > LONG_MAX || d < LONG_MIN) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That "|| d < LONG_MIN" looks strange, is it correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants