InputCommon: validate dynamic texture regions

Dynamic input texture JSON could specify rectangles outside the base
image. CopyImageRegion then wrote replacement pixels beyond the
destination vector, allowing a crafted local texture pack to corrupt
the heap.

Validate coordinates and image bounds at the parser and caller. Make
CopyImageRegion independently reject invalid source or destination
ranges.
This commit is contained in:
Acts1631 committed 2026-11-19 09:38:28 -05:00
1 parent 2fe1628662
commit fbe996f380
4 files changed
+68 -17

No files matched your search

@@ -159,6 +159,15 @@ void Configuration::GenerateTexture(const Common::IniFile& file,
for (const auto& rect : rects)
{
if (rect.right > image_to_write->width || rect.bottom > image_to_write->height)
{
ERROR_LOG_FMT(
VIDEO, "Dynamic input texture region ({}, {}, {}, {}) exceeds image '{}' ({}x{}).",
rect.left, rect.top, rect.right, rect.bottom, texture_data.m_image_name,
image_to_write->width, image_to_write->height);
continue;
}
InputCommon::ImagePixelData pixel_data;
if (host_key_image->width == rect.GetWidth() &&
host_key_image->height == rect.GetHeight())
@@ -177,9 +186,11 @@ void Configuration::GenerateTexture(const Common::IniFile& file,
Resize(ResizeMode::Nearest, *host_key_image, rect.GetWidth(), rect.GetHeight());
}
CopyImageRegion(pixel_data, *image_to_write,
Rect{0, 0, rect.GetWidth(), rect.GetHeight()}, rect);
dirty = true;
if (CopyImageRegion(pixel_data, *image_to_write,
Rect{0, 0, rect.GetWidth(), rect.GetHeight()}, rect))
{
dirty = true;
}
}
}
}