From ea37e71f873bfd56ad019b08951cb60c1682785f Mon Sep 17 00:00:00 2001 From: Anthony Nicholls Date: Tue, 14 Oct 2025 09:39:29 +0100 Subject: [PATCH] Time: Add assertions for issues parsing an ISO8601 formatted string --- modules/juce_core/time/juce_Time.cpp | 30 +++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/modules/juce_core/time/juce_Time.cpp b/modules/juce_core/time/juce_Time.cpp index db1f2420b9..4e2833a6a0 100644 --- a/modules/juce_core/time/juce_Time.cpp +++ b/modules/juce_core/time/juce_Time.cpp @@ -462,17 +462,26 @@ Time Time::fromISO8601 (StringRef iso) auto year = parseFixedSizeIntAndSkip (t, 4, '-'); if (year < 0) + { + jassertfalse; return {}; + } auto month = parseFixedSizeIntAndSkip (t, 2, '-'); if (month < 0) + { + jassertfalse; return {}; + } auto day = parseFixedSizeIntAndSkip (t, 2, 0); if (day < 0) + { + jassertfalse; return {}; + } int hours = 0, minutes = 0, milliseconds = 0; @@ -482,17 +491,26 @@ Time Time::fromISO8601 (StringRef iso) hours = parseFixedSizeIntAndSkip (t, 2, ':'); if (hours < 0) + { + jassertfalse; return {}; + } minutes = parseFixedSizeIntAndSkip (t, 2, ':'); if (minutes < 0) + { + jassertfalse; return {}; + } auto seconds = parseFixedSizeIntAndSkip (t, 2, 0); if (seconds < 0) - return {}; + { + jassertfalse; + return {}; + } if (*t == '.' || *t == ',') { @@ -500,7 +518,10 @@ Time Time::fromISO8601 (StringRef iso) milliseconds = parseFixedSizeIntAndSkip (t, 3, 0); if (milliseconds < 0) + { + jassertfalse; return {}; + } } milliseconds += 1000 * seconds; @@ -513,18 +534,25 @@ Time Time::fromISO8601 (StringRef iso) auto offsetHours = parseFixedSizeIntAndSkip (t, 2, ':'); if (offsetHours < 0) + { + jassertfalse; return {}; + } auto offsetMinutes = parseFixedSizeIntAndSkip (t, 2, 0); if (offsetMinutes < 0) + { + jassertfalse; return {}; + } auto offsetMs = (offsetHours * 60 + offsetMinutes) * 60 * 1000; milliseconds += nextChar == '-' ? offsetMs : -offsetMs; // NB: this seems backwards but is correct! } else if (nextChar != 0 && nextChar != 'Z') { + jassertfalse; return {}; }