Skip to content

Commit

Permalink
Formspec: prevent infinite loop caused by negative background9[] size (
Browse files Browse the repository at this point in the history
  • Loading branch information
SmallJoker committed Jul 7, 2023
1 parent 869df17 commit 078bd95
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/client/guiscalingfilter.cpp
Expand Up @@ -78,6 +78,7 @@ video::ITexture *guiScalingResizeCached(video::IVideoDriver *driver,
{
if (src == NULL)
return src;

if (!g_settings->getBool("gui_scaling_filter"))
return src;

Expand Down Expand Up @@ -114,6 +115,14 @@ video::ITexture *guiScalingResizeCached(video::IVideoDriver *driver,

// Create a new destination image and scale the source into it.
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(),
core::dimension2d<u32>((u32)destrect.getWidth(),
(u32)destrect.getHeight()));
Expand Down Expand Up @@ -160,6 +169,10 @@ void draw2DImageFilterScaled(video::IVideoDriver *driver, video::ITexture *txr,
const core::rect<s32> *cliprect, const video::SColor *const colors,
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.
video::ITexture *scaled = guiScalingResizeCached(driver, txr, srcrect, destrect);
if (scaled == NULL)
Expand Down

0 comments on commit 078bd95

Please sign in to comment.