Skip to content

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

Closed

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

Activity

  1. added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    type-bugAn unexpected behavior, bug, or error
    on Apr 25, 2025
  2. self-assigned this
    on Apr 25, 2025
  3. serhiy-storchaka commented on Apr 25, 2025

    @serhiy-storchaka
    Member

    wchar_t is at least 2 bytes on platforms supported by Python. wcslen() never returns result larger than SSIZE_MAX = SIZE_MAX/2.

  4. changed the title [-]Possible (benign) overflows for 'K' and 'u' format codes in `do_mkvalue`[/-] [+]Possible (benign) overflow for 'K' format codes in `do_mkvalue`[/+] on Apr 25, 2025
  5. changed the title [-]Possible (benign) overflow for 'K' format codes in `do_mkvalue`[/-] [+]Possible (benign) overflow for 'K' format code in `do_mkvalue`[/+] on Apr 25, 2025
  6. added 2 commits that reference this issue on Apr 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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