From 903460ff520cac8d0b3bd832b38593ee85b34787 Mon Sep 17 00:00:00 2001 From: mrmbernardi Date: Tue, 3 Sep 2024 04:21:49 +1000 Subject: [PATCH] Fix #22231: Invalid object version can cause a crash (#22675) --- distribution/changelog.txt | 1 + src/openrct2/object/Object.cpp | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 708ca31ca7..d41db57f70 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -1,5 +1,6 @@ 0.4.15 (in development) ------------------------------------------------------------------------ +- Fix: [#22231] Invalid object version can cause a crash. - Fix: [#22653] Add several .parkpatch files for missing water tiles in RCT1 and RCT2 scenarios. 0.4.14 (2024-09-01) diff --git a/src/openrct2/object/Object.cpp b/src/openrct2/object/Object.cpp index f379edc113..d3b0be75d9 100644 --- a/src/openrct2/object/Object.cpp +++ b/src/openrct2/object/Object.cpp @@ -405,12 +405,13 @@ ObjectVersion VersionTuple(std::string_view version) size_t highestIndex = std::min(nums.size(), VersionNumFields); for (size_t i = 0; i < highestIndex; i++) { - auto value = stoi(nums.at(i)); + auto value = stoll(nums.at(i)); constexpr auto maxValue = std::numeric_limits().max(); if (value > maxValue) { LOG_WARNING( - "Version value too high in version string '%s', version value will be capped to %i.", version, maxValue); + "Version value too high in version string '%.*s', version value will be capped to %i.", + static_cast(version.size()), version.data(), maxValue); value = maxValue; } versions[i] = value; @@ -418,7 +419,7 @@ ObjectVersion VersionTuple(std::string_view version) } catch (const std::exception&) { - LOG_WARNING("Malformed version string '%s', expected X.Y.Z", version); + LOG_WARNING("Malformed version string '%.*s', expected X.Y.Z", static_cast(version.size()), version.data()); } return std::make_tuple(versions[0], versions[1], versions[2]);