Bug 381810 - Krita does not load images with bogus file extensions.
Summary: Krita does not load images with bogus file extensions.
Status: RESOLVED FIXED
Alias: None
Product: krita
Classification: Applications
Component: File formats (show other bugs)
Version: 3.1.4
Platform: Microsoft Windows Microsoft Windows
: NOR minor
Target Milestone: ---
Assignee: Krita Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-06-30 00:59 UTC by Vox
Modified: 2017-12-15 14:00 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vox 2017-06-30 00:59:50 UTC
If an image is saved from a web browser as a different file type than it is viewed as in the browser (ie. saving a .jpg from a webpage as a .png), opening the file in Krita fails with the error message:

Could not open file:\\\[FILE_PATH]
Reason:Parsing error.

Opening the file in another image editor/graphics editor and overwriting it, or resaving as the same file type again, then allows the file to be opened by Krita correctly.
Comment 1 Halla Rempt 2017-06-30 08:01:16 UTC
If you save a png image with firefox with the jpg extension, it's still a png image, not a jpg image. And since krita tries to load it based on the extension, it will fail. I guess we could also inspect the file itself to see what format it really is, but then it would save to the wrong format (because that is also based on the extension) -- and you'd save a non-lossy png as a lossy jpg. I'm not sure that's a good idea.

In any case, _why_ would anyone do this?
Comment 2 Victor Wåhlström 2017-08-20 09:27:04 UTC
Other than accidentally saving as the wrong file extension, there are websites like imgur where you can change the extension in the URL and still get the same image. It's not converted, it just has the wrong extension.

One thing that can be done to improve the situation is to parse the header if there is a problem while loading the file, then either:

1. Notify the user of the problem, then attempt to "import" the image rather than opening it: Create a new file and load the data from the "opened" file into it. Since Krita won't have any references to the original file, saving will ask the user where to save the file instead of just overwriting the source file. 

or:

2. Keep the current behaviour of not opening the file, but improve the error message:

"Couldn't load file.jpg: Image format is actually png, not jpeg. Please change the file extension and try again."
Comment 3 Halla Rempt 2017-08-20 11:21:19 UTC
I like 1. a lot. And sure, we can do some file inspection. QMimeDatabase is actually supposed to be able to do that, but since it first checks the extension, it will only do the deeper inspection when it doesn't find a known extension.
Comment 4 Halla Rempt 2017-12-15 14:00:01 UTC
This is actually fixed now.