From 16b4e737a34ee36390a9bb84f9c6314c13419ad4 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Sat, 21 Sep 2024 15:04:35 +0100 Subject: [PATCH] Fix 3d8d0e0d26: Don't assume plural parameter is valid. (#12954) A crash can occur if the parameter used for a plural isn't a numeric value. --- src/strings.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/strings.cpp b/src/strings.cpp index 826a8bd4f6..7fa1bad9c1 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -1098,8 +1098,12 @@ static void FormatString(StringBuilder &builder, const char *str_arg, StringPara case SCC_PLURAL_LIST: { // {P} int plural_form = *str++; // contains the plural form for this string size_t offset = orig_offset + (uint8_t)*str++; - int64_t v = std::get(args.GetParam(offset)); // contains the number that determines plural - str = ParseStringChoice(str, DeterminePluralForm(v, plural_form), builder); + const uint64_t *v = std::get_if(&args.GetParam(offset)); // contains the number that determines plural + if (v != nullptr) { + str = ParseStringChoice(str, DeterminePluralForm(static_cast(*v), plural_form), builder); + } else { + builder += "(invalid PLURAL parameter)"; + } break; }