diff options
author | Nico Weber <thakis@chromium.org> | 2023-03-16 09:21:01 +0100 |
---|---|---|
committer | Tim Flynn <trflynn89@pm.me> | 2023-03-16 10:18:44 -0400 |
commit | 3a7257c9fe24f1c21a744a76e97f3ee7a2f42f7e (patch) | |
tree | 19bc5c428afa502c8a72021acbd968115c828f76 | |
parent | 0591aa1d9676b62427e374483ec5078613b4cc6c (diff) | |
download | serenity-3a7257c9fe24f1c21a744a76e97f3ee7a2f42f7e.zip |
image: Don't just crash when the input file can't be decoded
If the input file didn't exist at all, the TRY(MappedFile::map())
gives us a (cryptic) error message, but if it existed but wasn't an
image file, we would crash. Now we print a message instead.
-rw-r--r-- | Userland/Utilities/image.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/Userland/Utilities/image.cpp b/Userland/Utilities/image.cpp index 6f99b916f0..74d3654ba3 100644 --- a/Userland/Utilities/image.cpp +++ b/Userland/Utilities/image.cpp @@ -41,6 +41,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) auto file = TRY(Core::MappedFile::map(in_path)); auto decoder = Gfx::ImageDecoder::try_create_for_raw_bytes(file->bytes()); + if (!decoder) { + warnln("Failed to decode input file '{}'", in_path); + return 1; + } // This uses ImageDecoder instead of Bitmap::load_from_file() to have more control // over selecting a frame, access color profile data, and so on in the future. |