XPM values line with more than one space between numbers raises ValueError
メンテナーはふだん 1 日以内に返信
関連するプルリクエストがすでにマージされています。
- #10430 @Lushiyao5 による — マージ済み
評価
調査の方向性
issueで特定されたパターン xpm_head の箇所から PIL/XpmImagePlugin.py を読み始め、次にXPMプラグインのテストを探してください。提示されたvalues行で失敗を再現し、空白を処理した後に例が4×4のパレット画像として開くことを確認してください。報告者はPRの提出を申し出ていますが、担当者もリンクされたプルリクエストも記載されていません。
索引モデルが 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日 3時間
- マージ済み PR(30日)
- 185
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
python-pillow/Pillow のほかの issue
-
Converting F images to I turns large values, inf and NaN into -2147483648対応中かも @usmanmateen が 6 日前に担当しました。 オープン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 が 69 日前に担当しました。 オープンDocumentation Font Rendering PNG Third Party Framework
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
python-pillow/Pillow#9907 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
`ImageDraw.arc()` segfaults on a tuple subclass whose `__len__` is too large対応中かも @Parsiffall1 が 8 日前に担当しました。 オープン
難易度 4/5 1〜2日 初心者へのやさしさ 58/100
python-pillow/Pillow#10358 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
JPEG saved with keep_rgb=True and dpi reopens with incorrect colors対応中かも @Muguett-DBY が 9 日前に担当しました。 オープン🤖-assisted JPEG
難易度 4/5 1〜2日 初心者へのやさしさ 25/100
python-pillow/Pillow#10344 ·
メンテナーはふだん 1 日以内に返信
python-pillow/Pillow の issue をすべて見る
似ている issue
-
documentation good first issue
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
MarketSquare/robotframework-browser#5479 ·
メンテナーはふだん 1 日以内に返信
-
Visual COBOL: missing 11.0 and 12.0, and 9.0 date differs from Rocket Software's lifecycle pageオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
endoflife-date/endoflife.date#11561 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
OCA/l10n-brazil#5602 ·
メンテナーはふだん 1 日以内に返信
-
documentation review-2.0.0
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
dkuenzel/meshcore-home-gateway#106 ·
メンテナーはふだん 1 日以内に返信