From 3a7257c9fe24f1c21a744a76e97f3ee7a2f42f7e Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Thu, 16 Mar 2023 09:21:01 +0100 Subject: [PATCH] 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. --- Userland/Utilities/image.cpp | 4 ++++ 1 file changed, 4 insertions(+) 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 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.