pickle `load_build` function checks if `state` is None, not False
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
Bug report
Bug description:
Inside of the load_build() function for pickle's BUILD opcode, the C accelerator at one point checks if state is Py_None, while the Python version only checks if state.
https://github.com/python/cpython/blob/34ded1a1a10204635cad27830fcbee2f8547e8ed/Lib/pickle.py#L1765
This means if state is something like an empty dictionary or tuple, the code block under the if statement WILL be run in _pickle.c, but NOT in pickle.py.
As an example, the bytestream b']]b.' has the following disassembly:
0: ] EMPTY_LIST
1: ] EMPTY_LIST
2: b BUILD
3: . STOP
highest protocol among opcodes = 1
This will do nothing in pickle.py but error out in _pickle.c with the message state is not a dictionary. The easy solution is to change if state to if state != None, and it shouldn't break any existing functionality. I've attached a pull request.
CPython versions tested on:
3.11
Operating systems tested on:
Linux
Linked PRs
- gh-128966
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Compara el manejo de BUILD en Lib/pickle.py y Modules/_pickle.c, empezando por el flujo de bytes b']]b.' proporcionado y su desensamblado. Reproduce el comportamiento diferente y comprueba la cobertura de pruebas existente de pickle; se considera terminado cuando ambas implementaciones manejan de forma coherente los valores de estado falsy sin el error indicado.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- backend
- Tipo de issue
- Error
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 25/100