-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Trying to save a (0, 0) image creates an unreadable file #5944
Comments
I've created PR #5947 to resolve this. |
rather than removing file, why not create file only if there's no error? (i.e. don't open file if there's any known error) |
Ok, i've updated #5947 to use that method, rather than my original suggestion of removing the saved image after an error. |
I've restored my original idea of removing the file after the error as a new PR, #6134. I'm skeptical about the idea of forcing files to live in memory simply to handle this edge case. |
What happens if there's user's file with that filename?? btw, shouldn't |
Yes, if the user is asking Pillow to overwrite an existing file with the image, a corrupted image will still be saved. I don't understand your comment about |
what about: "before modifying on disk, check if it is saveable" OR ok. I thought it was to check if the file is |
It's unclear what "check if it is saveable" means without a significant change to how Pillow plugins work. Using a temporary file is possible, but again, it seems like a sizeable change to how Pillow operates, and this issue seems like a rare situation. Feel free to argue otherwise if you think this is a common situation, and my PR doesn't address it. |
about "check if saveable before saving", because most formats don't support (0,0) image, what about |
There is room for users to create their own plugins and add them to Pillow. Your suggestion could conceivably break plugins written by users. |
ok. This issue then probably could be a low priority. |
#6134 has now been merged, meaning that the broken file will be removed after the error has been raised. That should be part of Pillow 9.1.0, due out on April 1. If you don't think this is resolved, could you explain a bit more? I don't understand why it is important that a broken file not exist temporarily on disk. |
I think because:
so this issue probably could be a low priority, wait until probably found a better solution I guess |
It only removes the file if it didn't exist before Plllow started saving, so there should not be a risk of removing existing files. |
A common method I've seen in cases like this, is saving to a temporary file, and moving that file over the requested save path once it's successful. This also prevents partial saves (if pillow crashes halfway, you still end up with a valid file). My poor understanding is that there are different tradeoffs per operating system with this method. Ex. what happens if pillow crashes, does a temp file get left around? Who can access the temp file before it's deleted, and can they do anything different than with the requested save file path? |
@hugovk did you have any thoughts on this one? Essentially, the request is for Pillow plugins to be able to raise an error before the file is created. Our current code doesn't allow for this because the plugin code is only called after the file is created. Suggested solutions include
My only other idea is creating a wrapper around 3 is the solution I like best, but it seems like a sizeable change for a minor improvement, and errors can still be raised after a file has started to be written. It does resolve this issue, but perhaps not the larger problem. I'm inclined to close this as a wontfix. |
I'm also so inclined. Does it even make sense to create a Or on the |
#6159 has been merged, so a In summary, #6134 was merged, so newly created files will be removed after an error. There is a request here that Pillow not even start to write a |
What did you do?
What did you expect to happen?
no file should be created on disk because there's an
SystemError: tile cannot extend outside image
error.(#5931 (comment) for jpg, libjpeg seems not support size 0 0)
What actually happened?
throw
SystemError: tile cannot extend outside image
a ~33 bytes file is on disk, which is unable to read via pillow and other viewer No matter the extension is
.png
or.jpg
or.tiff
What are your OS, Python and Pillow versions?
The text was updated successfully, but these errors were encountered: