XPM values line with more than one space between numbers raises ValueError
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 86/100
Línea de trabajo
Empieza en PIL/XpmImagePlugin.py, en el patrón xpm_head identificado en la issue, y luego busca las pruebas del plugin XPM. Reproduce el fallo con la línea values proporcionada y comprueba que el ejemplo se abre como una imagen de paleta de 4×4 después de procesar los espacios en blanco. La persona que informa del problema se ofrece a enviar un PR, pero no consta ninguna persona asignada ni ninguna pull request vinculada.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
What did you do?
Opened an XPM file whose values line has more than one space between the numbers. GROMACS writes its matrix output this way (for example the RMSD matrix from gmx rms -m), and we ran into it in Galaxy when reading metadata from these files.
from io import BytesIO
from PIL import Image
data = b"""/* XPM */
static char *gromacs_xpm[] = {
"4 4 2 1",
"A c #FFFFFF ",
"B c #000000 ",
"ABAB",
"BABA",
"ABAB",
"BABA"
};
"""
with Image.open(BytesIO(data)) as im:
print(im.size, im.mode)
What did you expect to happen?
(4, 4) P
libXpm reads the values with xpmNextUI/xpmNextWord (src/data.c), which skips any run of whitespace before each number. ImageMagick also reads the file (XPM 4x4 8-bit sRGB 2c).
What actually happened?
File ".../PIL/XpmImagePlugin.py", line 59, in _open
palette_length = int(m.group(3))
ValueError: invalid literal for int() with base 10: b''
xpm_head matches exactly one space between the numbers:
xpm_head = re.compile(b'"([0-9]*) ([0-9]*) ([0-9]*) ([0-9]*)')
so with "4 4 2 1" the third group matches the empty string. With \s+ in place of the single spaces, the example opens as (4, 4) P and loads.
I'm happy to open a PR with that change and a test, if that sounds right to you.
What are your OS, Python and Pillow versions?
- OS: macOS 26.5.2 (arm64)
- Python: 3.14.2
- Pillow: 13.0.0 (also 12.3.0; the regex is unchanged on
main)
- Lenguaje dominante
- Python
- Estrellas
- 14k
- Forks
- 2.6k
- Merge medio
- 1 d 4 h
- PR fusionados (30 d)
- 182
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la 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.
Más de python-pillow/Pillow
-
Converting F images to I turns large values, inf and NaN into -2147483648Posiblemente ocupada @usmanmateen la tomó hace 5 días. AbiertoConversion
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
python-pillow/Pillow#10372 · 4 comentarios ·
Los mantenedores suelen responder en 1 día
-
Sun raster files with RLE encoding and odd-width rows decode shiftedPosiblemente ocupada @PerryLink la tomó hace 4 días. Abierto🤖-assisted
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
python-pillow/Pillow#10370 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
Warn that pre-applying arabic_reshaper + python-bidi corrupts text on a Raqm buildPosiblemente ocupada @Syamjith-NK la tomó hace 68 días. AbiertoDocumentation Font Rendering PNG Third Party Framework
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
python-pillow/Pillow#9907 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Image.putpixel incorrectly labels supported arguments in type annotationsPosiblemente ocupada @radarhere la tomó hace 196 días. AbiertoPNG
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
python-pillow/Pillow#9584 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
`ImageDraw.arc()` segfaults on a tuple subclass whose `__len__` is too largePosiblemente ocupada @Parsiffall1 la tomó hace 7 días. Abierto
Dificultad 4/5 1-2 días Aptitud para principiantes 58/100
python-pillow/Pillow#10358 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de python-pillow/Pillow
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
cline/mcp-marketplace#3576 ·
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
griptape-ai/griptape-nodes-library-elevenlabs#30 ·
Los mantenedores suelen responder en 1 día
-
docs: Release playbookAbiertodocumentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
awslabs/social-messaging-agent-runtime-toolkit#140 ·
Los mantenedores suelen responder en 1 día
-
subtask
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
fga-eps-mds/2026.2-MeasureSoftGram-DOC#187 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
NSPG13/agent-bounties#1747 ·
Los mantenedores suelen responder en 1 día