Skip to content

Ensure image is mutable before saving #3724

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 28, 2019

Conversation

radarhere
Copy link
Member

@radarhere radarhere commented Mar 17, 2019

Resolves #3496

In that issue, a bus error occurs when opening an image and saving it back to the same location. It was described as relating to mmap. Investigating, I find that the bus error occurs at

memcpy(out, in, pixels);

So presumably that is conflicting with mmap.

The same block of code that sets up mmap also marks the image as readonly.

Pillow/src/PIL/ImageFile.py

Lines 185 to 191 in d1f865e

with open(self.filename, "r") as fp:
self.map = mmap.mmap(fp.fileno(), 0,
access=mmap.ACCESS_READ)
self.im = Image.core.map_buffer(
self.map, self.size, decoder_name, extents,
offset, args)
readonly = 1

https://pillow.readthedocs.io/en/5.4.1/releasenotes/3.3.2.html

The image was marked readonly, so Pillow would not ordinarily write to that memory without duplicating the image first.

Given the general testing requirement of operating on temp files, and since the test involves opening and saving back the same file, the test can't be run on Windows, as temp files can't be opened twice on that operating system - https://docs.python.org/2/library/tempfile.html

Whether the name can be used to open the file a second time, while the named temporary file is still open, varies across platforms (it can be so used on Unix; it cannot on Windows NT or later).

@radarhere radarhere added the Bug Any unexpected behavior, until confirmed feature. label Mar 24, 2019
@hugovk hugovk merged commit a93bcdf into python-pillow:master Mar 28, 2019
@radarhere radarhere deleted the readonly_save branch March 28, 2019 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Any unexpected behavior, until confirmed feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants