From 4857ad1e00e506bd5d27d2d68dfa15fadcbaeff6 Mon Sep 17 00:00:00 2001 From: Rangi Date: Sat, 11 Jul 2026 13:18:40 -0400 Subject: [PATCH] Fix crash on image without any colors (all transparent) --- src/gfx/pal_packing.cpp | 2 ++ src/gfx/process.cpp | 5 +++++ test/gfx/no_colors.err | 2 ++ test/gfx/no_colors.png | Bin 0 -> 355 bytes 4 files changed, 9 insertions(+) create mode 100644 test/gfx/no_colors.err create mode 100644 test/gfx/no_colors.png diff --git a/src/gfx/pal_packing.cpp b/src/gfx/pal_packing.cpp index 2058476e..ccd47d77 100644 --- a/src/gfx/pal_packing.cpp +++ b/src/gfx/pal_packing.cpp @@ -279,6 +279,8 @@ static void verboseOutputAssignments( // LCOV_EXCL_STOP static void decant(std::vector &assignments, std::vector const &colorSets) { + assume(!assignments.empty()); + // "Decanting" is the process of moving all *things* that can fit in a lower index there auto decantOn = [&assignments](auto const &tryDecanting) { // No need to attempt decanting on palette #0, as there are no palettes to decant to diff --git a/src/gfx/process.cpp b/src/gfx/process.cpp index 02da54c4..ff6c193d 100644 --- a/src/gfx/process.cpp +++ b/src/gfx/process.cpp @@ -377,6 +377,7 @@ static std::pair, std::vector> pal.addColor(color); } } + assume(!palettes.empty()); // "Sort" colors in the generated palettes, see the man page for the flowchart if (options.palSpecType == Options::DMG) { @@ -1150,6 +1151,10 @@ continue_visiting_tiles:; } // LCOV_EXCL_STOP + if (colorSets.empty()) { + fatal("Image does not contain any colors"); + } + if (options.palSpecType == Options::EMBEDDED) { generatePalSpec(image); } diff --git a/test/gfx/no_colors.err b/test/gfx/no_colors.err new file mode 100644 index 00000000..88ae8352 --- /dev/null +++ b/test/gfx/no_colors.err @@ -0,0 +1,2 @@ +FATAL: Image does not contain any colors +Conversion aborted after 1 error diff --git a/test/gfx/no_colors.png b/test/gfx/no_colors.png new file mode 100644 index 0000000000000000000000000000000000000000..01e89278182aa431d8153d398c681e525eb112ff GIT binary patch literal 355 zcmeAS@N?(olHy`uVBq!ia0vp^93afW1|*O0@9PFqjKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1qucLCF%=h?3y^w370~qEv=}#LT=BJwMkF1yemk zJwqd5M)wk+q8+Ibo@t(*T3`!V8Kf9l85n`WUO+4jWrLif!N?32X9BVf8JQRafpioQ zXSTC|#dCmc5J&)GkbW4AZYu)=GXui}b_N!p8UrI^1I7gqb3uAo7eLIK24sT(6VN0k zu*x7y3m^-s%h138BztrDtf?orbH@Xj{GKk3AsWHS2@