1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:47:45 +00:00

LibGfx: Fail gracefully when trying to load invalid-sized HiDPI image

This commit is contained in:
Maciej 2022-02-01 23:29:05 +01:00 committed by Idan Horowitz
parent 592a51855c
commit c8183f2651

View file

@ -117,8 +117,8 @@ ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::try_load_from_file(String const& path, in
auto fd = TRY(Core::System::open(highdpi_icon_string, O_RDONLY));
auto bitmap = TRY(try_load_from_fd_and_close(fd, highdpi_icon_string));
VERIFY(bitmap->width() % scale_factor == 0);
VERIFY(bitmap->height() % scale_factor == 0);
if (bitmap->width() % scale_factor != 0 || bitmap->height() % scale_factor != 0)
return Error::from_string_literal("Bitmap::try_load_from_file: HighDPI image size should be divisible by scale factor");
bitmap->m_size.set_width(bitmap->width() / scale_factor);
bitmap->m_size.set_height(bitmap->height() / scale_factor);
bitmap->m_scale = scale_factor;