Formspec: prevent infinite loop caused by negative background9[] size (#13624)

This commit is contained in:
SmallJoker 2023-07-07 21:42:10 +02:00 committed by GitHub
parent 869df17ddf
commit 078bd95a49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -78,6 +78,7 @@ video::ITexture *guiScalingResizeCached(video::IVideoDriver *driver,
{ {
if (src == NULL) if (src == NULL)
return src; return src;
if (!g_settings->getBool("gui_scaling_filter")) if (!g_settings->getBool("gui_scaling_filter"))
return src; return src;
@ -114,6 +115,14 @@ video::ITexture *guiScalingResizeCached(video::IVideoDriver *driver,
// Create a new destination image and scale the source into it. // Create a new destination image and scale the source into it.
imageCleanTransparent(srcimg, 0); imageCleanTransparent(srcimg, 0);
if (destrect.getWidth() <= 0 || destrect.getHeight() <= 0) {
errorstream << "Attempted to scale texture to invalid size " << scalename.c_str() << std::endl;
// Avoid log spam by reusing and displaying the original texture
src->grab();
g_txrCache[scalename] = src;
return src;
}
video::IImage *destimg = driver->createImage(src->getColorFormat(), video::IImage *destimg = driver->createImage(src->getColorFormat(),
core::dimension2d<u32>((u32)destrect.getWidth(), core::dimension2d<u32>((u32)destrect.getWidth(),
(u32)destrect.getHeight())); (u32)destrect.getHeight()));
@ -160,6 +169,10 @@ void draw2DImageFilterScaled(video::IVideoDriver *driver, video::ITexture *txr,
const core::rect<s32> *cliprect, const video::SColor *const colors, const core::rect<s32> *cliprect, const video::SColor *const colors,
bool usealpha) bool usealpha)
{ {
// 9-sliced images might calculate negative texture dimensions. Skip them.
if (destrect.getWidth() <= 0 || destrect.getHeight() <= 0)
return;
// Attempt to pre-scale image in software in high quality. // Attempt to pre-scale image in software in high quality.
video::ITexture *scaled = guiScalingResizeCached(driver, txr, srcrect, destrect); video::ITexture *scaled = guiScalingResizeCached(driver, txr, srcrect, destrect);
if (scaled == NULL) if (scaled == NULL)