Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

`frombytes()` and in-place `ImageCms` transforms write into read-only image memory

Abierto
#10,235 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
50/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python
Área
backend

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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)
Lenguaje dominante
Python
Estrellas
13.9k
Forks
2.5k
Merge medio
1 d 3 h
PR fusionados (30 d)
135

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de python-pillow/Pillow

Todos los issues de python-pillow/Pillow

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.