GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — PyLong_FromString() does not always set `*pend` on error · Issue #110865 · python/cpython

PyLong_FromString() does not always set *pend on error #110865

New issue
Copy link
New issue
Copy link
Open
Open
PyLong_FromString() does not always set *pend on error#110865
Copy link
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-C-APItype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@serhiy-storchaka
serhiy-storchaka
opened on Oct 14, 2023
Issue body actions

According to the documentation, PyLong_FromString() sets *pend (if pend is not NULL) to the first character that could not be processed on error. But it does not do this in the following cases:

  1. base is invalid (not 0 or in range from 2 to 36).
  2. Binary base number exceeds sys.maxsize bits.
  3. Decimal number exceeds the limit of digits sys.get_int_max_str_digits().
  4. Other base numbers also have limits.
  5. Memory allocation error.
  6. User presses Ctrl-C when _pylong.int_from_string() is used.

The workaround is to initialize the pointer to some known value, for example the start of the string or NULL before using PyLong_FromString(). If initialize it to NULL, we can distinguish ValueError raised for invalid base or exceeding the sys.get_int_max_str_digits() limit from ValueError raised for invalid string content.

We should either document this and require initialization of the end pointer, or always set it on error in PyLong_FromString(). The latter is a potentially breaking change, because it can override the sentinel value used in the user code. But the former looks like bad design.

Activity

  1. serhiy-storchaka
    added
    3.11only security fixesonly security fixes
    topic-C-API
    3.12only security fixesonly security fixes
    3.13only security fixesonly security fixes
    on Oct 14, 2023
  2. encukou commented on Oct 17, 2023

    @encukou
    encukou
    on Oct 17, 2023
    Member
    More actions

    Setting it to NULL might make existing code crash, and does not follow the current documentation. IMO, that makes it a no-go.
    So, IMO it should be set to the start of the string.

    Distinguishing e.g. ValueError from invalid base from ValueError from string contents doesn't seem that useful to me.
    If it is useful, IMO we should add specialized API with a richer set of errors states it can report.

  3. skirpichev
    removed
    3.11only security fixesonly security fixes
    3.12only security fixesonly security fixes
    on Apr 19, 2025
  4. picnixz
    added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    and removed
    3.13only security fixesonly security fixes
    on Apr 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.