python / python/cpython

Add `limit=` keyword to `int()` and `str()` functions to avoid contention on global `PYTHONINTMAXSTRDIGITS`

Ouverte
#98,547 8 commentaires 4 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

3.13 interpreter-core type-feature
Langage dominant
Python
Étoiles
77.2k
Forks
36k
Métriques de merge des PR
Métriques de PR en attente

Description

Enhancement

With the mitigations for CVE-2020-10735 in place, there's tension between:

  • security-minded folks which need to protect against DoS attacks
  • scientific (and other) use-cases which need to process large numbers in some form

Those are both vying for the one setting (PYTHONINTMAXSTRDIGITS) that controls this, which is unfortunately global state.

Since several such libraries are often loaded in the same runtime, this makes it very tricky to balance.

The idea is simply to add a limit=None keyword to int() and str(), which defaults to PYTHONINTMAXSTRDIGITS if None, but can be set to any other value. Setting it to 0 (for example, or -1) would make it unlimited.

Pitch

This would not solve all the fallout right away, but it would provide a sane path forward, where the default can be safe, and callsites can explicitly opt into saying "I want this call to have a different limit".

In particular, it would not require global state to balance the divergent needs of different parts of the ecosystem anymore.

In case a spectacular new conversion algorithm comes along, the default could eventually be set to infinite again, but the API wouldn't stand out as useless/harmful, but still serve a clear purpose, and so this proposal is independent of future string algorithms or default limits.

Previous discussion

https://discuss.python.org/t/int-str-conversions-broken-in-latest-python-bugfix-releases/18889/
and many more places linked from there

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par la proposition liée sur discuss.python.org et la discussion qu’elle référence, puis examinez comment CPython applique actuellement PYTHONINTMAXSTRDIGITS aux conversions int() et str(). L’issue ne nomme aucun fichier source ni aucun test ; le comportement de l’API, le périmètre de l’implémentation et la couverture devraient donc être définis d’un commun accord avant de commencer le travail.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
python
Domaine
compilers
Type d'issue
Fonctionnalité
Difficulté
5/5
Temps estimé
Plus d'une semaine
Activité
À l'abandon
Clarté
À clarifier
Accessibilité débutants
18/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.