Make recently added wxXPMDecoder test case really pass

We need to use memmove() and not strncpy() in wxXPMDecoder code as
nothing guarantees that the source and destination regions don't overlap
and they did overlap, in fact, for the test case added as part of
46f928d057 (Fix buffer overflow on invalid width in wxXPMDecoder,
2026-05-27).

Also make the test itself more explicit by hard-coding the test XPM
instead of constructing it dynamically.

See #26519.
This commit is contained in:
Vadim Zeitlin
2026-05-30 23:02:11 +02:00
parent cf50020259
commit ccff9fe0f3
2 changed files with 6 additions and 7 deletions
+5 -6
View File
@@ -1552,12 +1552,11 @@ TEST_CASE_METHOD(ImageHandlersInit, "wxImage::BadXPMWidthOverflow",
// wraps to 59, so a one-pixel image line passes the length check and the
// key-reading loop then runs off the end of the buffer. Loading such a
// file must be rejected.
const std::string key(63, 'a');
const std::string xpm =
"/* XPM */\n"
"\"68174085 1 1 63\"\n"
"\"" + key + " c #ffffff\"\n"
"\"" + key + "\"\n";
const std::string xpm = R"("/* XPM */"
"68174085 1 1 63"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa c #ffffff"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
)";
wxMemoryInputStream mis(xpm.data(), xpm.size());
wxImage img;
REQUIRE( !img.LoadFile(mis, wxBITMAP_TYPE_XPM) );