XPM values line with more than one space between numbers raises ValueError
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 86/100
Direzione di ricerca
Inizia da PIL/XpmImagePlugin.py, dal pattern xpm_head identificato nell’issue, poi trova i test del plugin XPM. Riproduci il problema con la riga values fornita e verifica che l’esempio si apra come immagine a palette 4×4 dopo aver gestito gli spazi bianchi. Chi ha segnalato il problema si offre di inviare una PR, ma non è indicato alcun assegnatario né alcuna pull request collegata.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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)
- Lingua principale
- Python
- Stelle
- 14k
- Fork
- 2.6k
- Merge medio
- 1g 4h
- PR unite (30g)
- 182
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di python-pillow/Pillow
-
Converting F images to I turns large values, inf and NaN into -2147483648Forse già presa @usmanmateen l’ha presa 5 giorni fa. ApertaConversion
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
python-pillow/Pillow#10372 · 4 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Sun raster files with RLE encoding and odd-width rows decode shiftedForse già presa @PerryLink l’ha presa 4 giorni fa. Aperta🤖-assisted
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
python-pillow/Pillow#10370 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Warn that pre-applying arabic_reshaper + python-bidi corrupts text on a Raqm buildForse già presa @Syamjith-NK l’ha presa 68 giorni fa. ApertaDocumentation Font Rendering PNG Third Party Framework
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
python-pillow/Pillow#9907 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Image.putpixel incorrectly labels supported arguments in type annotationsForse già presa @radarhere l’ha presa 196 giorni fa. ApertaPNG
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
python-pillow/Pillow#9584 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
`ImageDraw.arc()` segfaults on a tuple subclass whose `__len__` is too largeForse già presa @Parsiffall1 l’ha presa 7 giorni fa. Aperta
Difficoltà 4/5 1-2 giorni Idoneità per principianti 58/100
python-pillow/Pillow#10358 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di python-pillow/Pillow
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
cline/mcp-marketplace#3576 ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
griptape-ai/griptape-nodes-library-elevenlabs#30 ·
I maintainer di solito rispondono entro 1 giorno
-
docs: Release playbookApertadocumentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
awslabs/social-messaging-agent-runtime-toolkit#140 ·
I maintainer di solito rispondono entro 1 giorno
-
subtask
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
fga-eps-mds/2026.2-MeasureSoftGram-DOC#187 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
NSPG13/agent-bounties#1747 ·
I maintainer di solito rispondono entro 1 giorno