XPM values line with more than one space between numbers raises ValueError
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 86/100
Hướng nghiên cứu
Bắt đầu tại PIL/XpmImagePlugin.py, ở mẫu xpm_head được xác định trong issue, rồi tìm các bài kiểm tra của plugin XPM. Tái hiện lỗi bằng dòng values được cung cấp và kiểm tra xem ví dụ có mở thành ảnh bảng màu 4×4 sau khi xử lý khoảng trắng hay không. Người báo cáo đề nghị gửi PR, nhưng không có người được giao xử lý hay pull request liên kết nào được liệt kê.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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)
- Ngôn ngữ chính
- Python
- Star
- 14k
- Fork
- 2.6k
- Merge trung bình
- 1 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 182
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của python-pillow/Pillow
-
Converting F images to I turns large values, inf and NaN into -2147483648Có thể đã có người làm @usmanmateen đã nhận 5 ngày trước. Đang mởConversion
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
python-pillow/Pillow#10372 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Sun raster files with RLE encoding and odd-width rows decode shiftedCó thể đã có người làm @PerryLink đã nhận 4 ngày trước. Đang mở🤖-assisted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
python-pillow/Pillow#10370 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Warn that pre-applying arabic_reshaper + python-bidi corrupts text on a Raqm buildCó thể đã có người làm @Syamjith-NK đã nhận 68 ngày trước. Đang mởDocumentation Font Rendering PNG Third Party Framework
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
python-pillow/Pillow#9907 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Image.putpixel incorrectly labels supported arguments in type annotationsCó thể đã có người làm @radarhere đã nhận 196 ngày trước. Đang mởPNG
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
python-pillow/Pillow#9584 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`ImageDraw.arc()` segfaults on a tuple subclass whose `__len__` is too largeCó thể đã có người làm @Parsiffall1 đã nhận 7 ngày trước. Đang mở
Độ khó 4/5 1-2 ngày Mức phù hợp với người mới 58/100
python-pillow/Pillow#10358 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của python-pillow/Pillow
Issue tương tự
-
docs: Release playbookĐang mởdocumentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
awslabs/social-messaging-agent-runtime-toolkit#140 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
subtask
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
fga-eps-mds/2026.2-MeasureSoftGram-DOC#187 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
txn2/mcp-data-platform#2493 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
YO-WHATS-UP2/minigit#78 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
liberation-data/drivine-python#432 ·
Maintainer thường phản hồi trong vòng 1 ngày