XPM values line with more than one space between numbers raises ValueError
维护者通常 1 天内回复
评估
调研方向
从 issue 中确定的 xpm_head 模式处开始查看 PIL/XpmImagePlugin.py,然后找到 XPM 插件的测试。使用提供的 values 行重现故障,并检查处理空白后示例是否能作为 4×4 调色板图像打开。报告者愿意提交 PR,但未列出负责人或关联的 pull request。
由索引模型根据 Issue 内容生成。
描述
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)
- 主要语言
- Python
- 星标
- 14k
- 派生
- 2.6k
- 平均合并
- 1 天 4 小时
- 30 天内合并 PR
- 182
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
python-pillow/Pillow 的其他 Issue
-
Converting F images to I turns large values, inf and NaN into -2147483648可能已有人在做 @usmanmateen 于 5 天前认领。 未关闭Conversion
难度 2/5 1-3 小时 新手友好度 72/100
python-pillow/Pillow#10372 · 4 条评论 ·
维护者通常 1 天内回复
-
Sun raster files with RLE encoding and odd-width rows decode shifted可能已有人在做 @PerryLink 于 5 天前认领。 未关闭🤖-assisted
难度 2/5 1-3 小时 新手友好度 72/100
python-pillow/Pillow#10370 · 3 条评论 ·
维护者通常 1 天内回复
-
Warn that pre-applying arabic_reshaper + python-bidi corrupts text on a Raqm build可能已有人在做 @Syamjith-NK 于 68 天前认领。 未关闭Documentation Font Rendering PNG Third Party Framework
难度 2/5 1-3 小时 新手友好度 78/100
python-pillow/Pillow#9907 · 2 条评论 ·
维护者通常 1 天内回复
-
Image.putpixel incorrectly labels supported arguments in type annotations可能已有人在做 @radarhere 于 196 天前认领。 未关闭PNG
难度 2/5 1-3 小时 新手友好度 70/100
python-pillow/Pillow#9584 · 1 条评论 ·
维护者通常 1 天内回复
-
`ImageDraw.arc()` segfaults on a tuple subclass whose `__len__` is too large可能已有人在做 @Parsiffall1 于 7 天前认领。 未关闭
难度 4/5 1-2 天 新手友好度 58/100
python-pillow/Pillow#10358 · 2 条评论 ·
维护者通常 1 天内回复
查看 python-pillow/Pillow 的全部 Issue
相似的 Issue
-
request-theme
难度 1/5 1 小时以内 新手友好度 78/100
LizardByte/ThemerrDB#9883 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
Project-MONAI/MONAI#9258 ·
维护者通常 3 天内回复
-
catalog:deprecation
难度 1/5 1 小时以内 新手友好度 88/100
surendranb/free-inference#31 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
fritzprix/libr-agent#2612 ·
维护者通常 1 天内回复
-
needs-triage presubmit-gate
难度 2/5 1-3 小时 新手友好度 76/100
gke-labs/kube-agents#5001 ·
维护者通常 1 天内回复