Pickle `load_build` function checks if `slotstate` is False, not a dict
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 77.2k
- Forks
- 35.9k
- Métriques de merge des PR
- Métriques de PR en attente
Description
Bug report
Bug description:
This issue is similar to Issue https://github.com/python/cpython/issues/128965. Inside of the load_build() function, Python pickle assumes that slotstate is a dictionary while C _pickle explicitly checks to ensure it's a dictionary. The behavior of these two implementations diverge when slotstate is falsey but not a dictionary.
payload: b'NN\x8f\x86b.'
pickle: None
_pickle.c: FAILURE slot state is not a dictionary
pickletools:
0: N NONE
1: N NONE
2: \x8f EMPTY_SET
3: \x86 TUPLE2
4: b BUILD
5: . STOP
highest protocol among opcodes = 4
In this case, opcode 2 (EMPTY_SET) is slotstate. When running in pickle.py, this is falsey and thus the code inside setting attributes will not be run, causing the pickle to continue deserializing without any errors.
https://github.com/python/cpython/blob/29acc08c8dad664cd5713cb392e5beba65724c10/Lib/pickle.py#L1868
When running in _pickle.c, this value is not a dictionary, causing an error to be thrown.
I guess also in general I'm not understanding what the if slotstate in pickle.py is meant to do anyway. If it's supposed to check if slotstate == None, then the C _pickle module doesn't do that correctly. It checks if slotstate is NULL, which is not the same as PyNone.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
- gh-144582
Guide de contribution
Ouvrir 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.
Piste de recherche
Comparez l’implémentation de load_build dans Lib/pickle.py avec Modules/_pickle.c, en utilisant le payload b'NN\x8f\x86b.' pour reproduire le comportement divergent. Examinez le PR lié gh-144582 et confirmez que les deux implémentations rejettent systématiquement un slotstate falsy qui n’est pas un dictionnaire, le comportement pertinent de pickle étant couvert par des tests si le PR les identifie.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- backend
- Type d'issue
- Bug
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100