`frombytes()` and in-place `ImageCms` transforms write into read-only image memory
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 50/100
Hướng nghiên cứu
Start with Image.frombytes() and ImageCmsTransform.apply() in Pillow’s image and ImageCms implementations, then trace how their callers handle readonly memory. Run the reproduction snippets in the issue and inspect related mutability tests. Done means writes to read-only image buffers no longer crash or alter the source data, while plugin loading avoids extra copies and recursion.
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?
Called frombytes() on an image opened from an uncompressed TIFF, which Pillow maps into memory read-only:
from PIL import Image
Image.new("RGBA", (64, 64)).save("test.tif")
with Image.open("test.tif") as im:
im.load()
im.frombytes(b"\x01" * 64 * 64 * 4)
An in-place colour transform does the same, even without load():
from PIL import Image, ImageCms
srgb = ImageCms.createProfile("sRGB")
with Image.open("test.tif") as im:
ImageCms.profileToProfile(im, srgb, srgb, inPlace=True)
And frombytes() on an image made by frombuffer() from bytes:
from PIL import Image
data = bytes(64)
im = Image.frombuffer("L", (8, 8), data, "raw", "L", 0, 1)
im.frombytes(b"\x01" * 64)
print(data[:4])
What did you expect to happen?
The same as with paste(), putpixel(), putdata() or putalpha(): the image is copied first and the copy is changed, while the file and data stay as they were.
What actually happened?
The first two crash, with a bus error on macOS and a segmentation fault on Linux. The third prints b'\x01\x01\x01\x01': the bytes object was changed. An image from Image.fromarrow() behaves the same way, the new values end up in the Arrow array.
frombytes() gives self.im to the decoder without looking at readonly, and ImageCmsTransform.apply(im, imOut), which inPlace=True uses, writes into imOut the same way. The methods above call _ensure_mutable() first.
This fixes it for me, and the test suite still passes:
# Image.frombytes(), after the zero-size check
if self.im.readonly:
self._copy()
# ImageCmsTransform.apply()
if imOut is None:
imOut = Image.new(self.output_mode, im.size)
else:
imOut._ensure_mutable()
I did not use _ensure_mutable() in frombytes() because plugins call frombytes() from their own load(), while ImageFile.readonly is still 1. Every GbrImagePlugin and WalImageFile image would be copied once more, and a plugin that marks itself loaded only after frombytes() (pillow-heif 1.8.1, for example) ends in RecursionError.
We ran into this while moving pillow-heif to Image.fromarrow() (https://github.com/bigcat88/pillow_heif/pull/463, after #9896).
What are your OS, Python and Pillow versions?
- OS: macOS 26.5 arm64, Linux aarch64 (Docker
python:3.11-slim) - Python: 3.11
- Pillow: 12.3.0, 13.0.0 and
main(6085656)
- Ngôn ngữ chính
- Python
- Star
- 13.9k
- Fork
- 2.5k
- Merge trung bình
- 1 ngày 3 giờ
- Pull request đã merge (30 ngày)
- 135
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
-
Warn that pre-applying arabic_reshaper + python-bidi corrupts text on a Raqm buildCó thể đã có người làm @Syamjith-NK đã nhận 51 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 179 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
-
Future of JPEG2000 supportĐang mởJPEG
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
python-pillow/Pillow#10241 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
ImageDraw is not translation-invariant for negative coordinates (truncation toward zero instead of floor)Có thể đã có người làm @Eryx-Z đã nhận 3 ngày trước. Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 38/100
python-pillow/Pillow#10228 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
python-pillow/Pillow#10191 · 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ự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
mihai-vlc/sublime-jsfmt#56 ·
-
comp/cli comp/plugins P2 type/bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
NousResearch/hermes-agent#141917 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Go device SDK: Whisper transcriber keeps buffering and transcribing audio appended after Stop()Có thể đã có người làm @apoorvdarshan đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
BasedHardware/omi#22770 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug needs-acceptance wg/router-models-inference-runtime
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
vllm-project/semantic-router#5295 ·
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 84/100
huggingface/huggingface_hub#5210 ·
Maintainer thường phản hồi trong vòng 1 ngày