The punycode incremental encoder and decoder transform each chunk separately
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
- #160599 par @OsmnvAslan — fermée sans fusion
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 72/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- python
- Domaine
- backend, internationalization
Piste de recherche
Read Lib/encodings/punycode.py around lines 226–234 and the buffered incremental encoder and decoder base classes. Check how idna buffers input and how test_codecs.py marks punycode as broken in stateful mode. Implement buffering until final for both directions, then verify chunked input produces the same result as the whole-string transform.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Bug description
encodings.punycode registers an IncrementalEncoder and IncrementalDecoder, but they just run the whole-string transform on every chunk they are given, so anything fed in more than one piece comes out wrong:
>>> import codecs
>>> 'ab'.encode('punycode')
b'ab-'
>>> encoder = codecs.getincrementalencoder('punycode')()
>>> encoder.encode('a') + encoder.encode('b', final=True)
b'a-b-'
>>> b'a-b-'.decode('punycode')
'a-b'
Punycode encodes the positions of the non-ASCII characters relative to the whole label, so a chunk cannot be encoded without the rest of the string; the same goes for decoding. The classes are two lines each, Lib/encodings/punycode.py lines 226-234, and ignore final altogether. This is half known: test_codecs.py lists punycode in broken_unicode_with_stateful ("encodings that don't work in stateful mode") and skips the chunked part of test_basics for it, but nothing says so in the docs, and the classes are still registered and handed out by codecs.getincrementalencoder(), codecs.iterencode() and StreamWriter.
I think the right fix is to buffer until final (the BufferedIncrementalEncoder and BufferedIncrementalDecoder base classes make that a few lines: _buffer_encode returns (b'', 0) until final), since that keeps codecs.iterencode, StreamWriter and friends working for anyone who hands them the whole label at once, which is presumably every current user. The idna codec already does something like it, buffering up to each ..
Related: #64331 (many incremental codecs do not handle fragmented data) mentions punycode in passing, in a list taken from that same test_codecs.py entry, but does not go into it.
Found by the Hypothesis tests in #160155, where it is pinned as PunycodeIncrementalBug.test_chunked_encode under expectedFailure; the chunked tests there leave punycode out otherwise.
CPython versions tested on
CPython main (6e1bd24e4d8)
Operating systems tested on
Linux
- Langage dominant
- Python
- Étoiles
- 77.7k
- Forks
- 38.3k
- Merge moyen
- 14 h 29 min
- PR mergées (30 j)
- 699
Préparer son environnement
Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de python/cpython
-
topic-socket type-bug
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
python/cpython#160561 · 7 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
tests topic-profiling type-bug
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
python/cpython#160334 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
extension-modules type-bug
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
Les mainteneurs répondent en général sous 1 jour
-
Remove unused FVS_* macrosOuverteinterpreter-core type-feature
Difficulté 1/5 Moins d'une heure Accessibilité débutants 78/100
python/cpython#160109 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
extension-modules type-bug
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
python/cpython#160001 · 3 commentaires ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de python/cpython
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
NVIDIA/flare-local-inference#90 ·
Les mainteneurs répondent en général sous 1 jour
-
area/streaming comp/gateway P2 platform/telegram type/bug
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
NousResearch/hermes-agent#144897 ·
Les mainteneurs répondent en général sous 1 jour
-
request-theme
Difficulté 1/5 Moins d'une heure Accessibilité débutants 66/100
LizardByte/ThemerrDB#9575 ·
Les mainteneurs répondent en général sous 1 jour
-
Author Page: noshin-nawalOuverteauthor-page correction
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
acl-org/acl-anthology#10599 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
zilliztech/memsearch#818 ·
Les mainteneurs répondent en général sous 1 jour