From fbe996f380c717d6d15a8cf5577146ee251aaa1d Mon Sep 17 00:00:00 2001 From: Acts1631 Date: Fri, 13 Nov 2026 14:21:15 -0500 Subject: 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. --- .../DynamicInputTextures/DITSpecification.cpp | 34 ++++++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) (limited to 'Source/Core/InputCommon/DynamicInputTextures/DITSpecification.cpp') diff --git a/Source/Core/InputCommon/DynamicInputTextures/DITSpecification.cpp b/Source/Core/InputCommon/DynamicInputTextures/DITSpecification.cpp index 7b2b15a80b..902a2d11f8 100644 --- a/Source/Core/InputCommon/DynamicInputTextures/DITSpecification.cpp +++ b/Source/Core/InputCommon/DynamicInputTextures/DITSpecification.cpp @@ -3,6 +3,9 @@ #include "InputCommon/DynamicInputTextures/DITSpecification.h" +#include +#include + #include #include "Common/FileUtil.h" @@ -11,6 +14,25 @@ namespace InputCommon::DynamicInputTextures { +namespace +{ +bool ReadCoordinate(const picojson::value& value, u32* coordinate) +{ + if (!value.is()) + return false; + + const double number = value.get(); + if (!std::isfinite(number) || number < 0 || + number > static_cast(std::numeric_limits::max()) || std::trunc(number) != number) + { + return false; + } + + *coordinate = static_cast(number); + return true; +} +} // namespace + bool ProcessSpecificationV1(picojson::value& root, std::vector& input_textures, const std::string& base_path, const std::string& json_file) { @@ -135,20 +157,20 @@ bool ProcessSpecificationV1(picojson::value& root, std::vector& input_text return false; } - if (!std::ranges::all_of(region_offsets, &picojson::value::is)) + if (!ReadCoordinate(region_offsets[0], &r.left) || + !ReadCoordinate(region_offsets[1], &r.top) || + !ReadCoordinate(region_offsets[2], &r.right) || + !ReadCoordinate(region_offsets[3], &r.bottom) || r.left >= r.right || + r.top >= r.bottom) { ERROR_LOG_FMT( VIDEO, "Failed to load dynamic input json file '{}' because emulated controller '{}' " - "key '{}' has a region that has the incorrect offset type.", + "key '{}' has an invalid region.", json_file, emulated_controller_name, emulated_control); return false; } - r.left = static_cast(region_offsets[0].get()); - r.top = static_cast(region_offsets[1].get()); - r.right = static_cast(region_offsets[2].get()); - r.bottom = static_cast(region_offsets[3].get()); region_rects.push_back(r); } key_to_regions.insert_or_assign(emulated_control, std::move(region_rects)); -- cgit v1.2.3