diff --git a/Tests/LibGfx/TestImageDecoder.cpp b/Tests/LibGfx/TestImageDecoder.cpp index f36a6afe35..001b68acea 100644 --- a/Tests/LibGfx/TestImageDecoder.cpp +++ b/Tests/LibGfx/TestImageDecoder.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -617,3 +618,18 @@ TEST_CASE(test_jxl_modular_property_8) } } } + +TEST_CASE(test_dds) +{ + Array file_names = { + TEST_INPUT("dds/catdog-alert-29x29.dds"sv), + TEST_INPUT("dds/catdog-alert-32x32.dds"sv) + }; + + for (auto file_name : file_names) { + auto file = MUST(Core::MappedFile::map(file_name)); + EXPECT(Gfx::DDSImageDecoderPlugin::sniff(file->bytes())); + auto plugin_decoder = MUST(Gfx::DDSImageDecoderPlugin::create(file->bytes())); + expect_single_frame(*plugin_decoder); + } +} diff --git a/Tests/LibGfx/test-inputs/dds/catdog-alert-29x29.dds b/Tests/LibGfx/test-inputs/dds/catdog-alert-29x29.dds new file mode 100644 index 0000000000..9bca08b5ed Binary files /dev/null and b/Tests/LibGfx/test-inputs/dds/catdog-alert-29x29.dds differ diff --git a/Tests/LibGfx/test-inputs/dds/catdog-alert-32x32.dds b/Tests/LibGfx/test-inputs/dds/catdog-alert-32x32.dds new file mode 100644 index 0000000000..bc7e1d02d7 Binary files /dev/null and b/Tests/LibGfx/test-inputs/dds/catdog-alert-32x32.dds differ diff --git a/Userland/Libraries/LibGfx/ImageFormats/DDSLoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/DDSLoader.cpp index 14b02be0f6..00dbb1557c 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/DDSLoader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/DDSLoader.cpp @@ -253,8 +253,8 @@ static ErrorOr decode_dx5_alpha_block(Stream& stream, DDSLoadingContext& c color[7] = 255; } - for (size_t y = 0; y < 4; y++) { - for (size_t x = 0; x < 4; x++) { + for (size_t y = 0; y < 4 && bitmap_y + y < static_cast(context.bitmap->height()); y++) { + for (size_t x = 0; x < 4 && bitmap_x + x < static_cast(context.bitmap->width()); x++) { u8 index = 3 * (4 * y + x); u8 bit_location = floor(index / 8.0); u8 adjusted_index = index - (bit_location * 8); @@ -284,8 +284,8 @@ static ErrorOr decode_dx3_alpha_block(Stream& stream, DDSLoadingContext& c u64 alpha_0 = a0 + 256u * (a1 + 256u * (a2 + 256u * (a3 + 256u))); u64 alpha_1 = a4 + 256u * (a5 + 256u * (a6 + 256u * a7)); - for (size_t y = 0; y < 4; y++) { - for (size_t x = 0; x < 4; x++) { + for (size_t y = 0; y < 4 && bitmap_y + y < static_cast(context.bitmap->height()); y++) { + for (size_t x = 0; x < 4 && bitmap_x + x < static_cast(context.bitmap->width()); x++) { u8 code = 4 * (4 * y + x); if (code >= 32) { @@ -357,8 +357,8 @@ static ErrorOr decode_color_block(Stream& stream, DDSLoadingContext& conte } size_t i = 0; - for (size_t y = 0; y < 4; y++) { - for (size_t x = 0; x < 4; x++) { + for (size_t y = 0; y < 4 && bitmap_y + y < static_cast(context.bitmap->height()); y++) { + for (size_t x = 0; x < 4 && bitmap_x + x < static_cast(context.bitmap->width()); x++) { u8 code_byte = (code >> (i * 2)) & 3; u8 r = rgba[code_byte][0]; u8 g = rgba[code_byte][1];