Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

guiScalingFilter: prevent infinite loop caused by negative background9[] size #13624

Merged
merged 1 commit into from
Jul 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/client/guiscalingfilter.cpp
Original file line number Diff line number Diff line change
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