Skip to content

Possible (benign) overflow for 'K' format code in do_mkvalue #132909

Closed
@picnixz

Description

@picnixz

Bug report

Bug description:

This is probably not an issue but here are the known "temporary" overflows:

// format = 'K'
return PyLong_FromUnsignedLongLong((long long)va_arg(*p_va, unsigned long long));

Note that va_arg(*p_va, unsigned long long) will be converted into an unsigned long long, and then into a long long, and then back to an unsigned long long. So if we were to have an overflow here, it shouldn't really matter. Indeed, take v = (1ULL << 63) + 2. We have:

unsigned long long v2 = va_arg(*p_va, unsigned long long);
// v2 = 9223372036854775810
long long v3 = (long long)v2;
// v3 = -9223372036854775806
PyObject *v4 = PyLong_FromUnsignedLongLong(v3);
// v4 = 9223372036854775810 as PyObject as v3 was casted back to an unsigned long long

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

Metadata

Metadata

Assignees

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)topic-C-APItype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions