Fix CHECK() in CFGAS_StringFormatter::FormatDateTime()
Confirmed that optimizer has removed one int3/ud2 trap from
binary as a result.
Bug: pdfium:1268
Change-Id: I001b291a53ffafdb64f3cda99de5432478d41970
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/52192
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/xfa/fgas/crt/cfgas_stringformatter.cpp b/xfa/fgas/crt/cfgas_stringformatter.cpp
index fca1971..9c7d0f2 100644
--- a/xfa/fgas/crt/cfgas_stringformatter.cpp
+++ b/xfa/fgas/crt/cfgas_stringformatter.cpp
@@ -788,7 +788,7 @@
uint32_t second = 0;
uint32_t millisecond = 0;
- if (spTime[cc] != 'Z') {
+ if (cc < spTime.size() && spTime[cc] != 'Z') {
if (!ExtractCountDigits(spTime, 2, &cc, &second) || second >= 60)
return false;
diff --git a/xfa/fgas/crt/cfgas_stringformatter_unittest.cpp b/xfa/fgas/crt/cfgas_stringformatter_unittest.cpp
index 64e7d8a..3fa3032 100644
--- a/xfa/fgas/crt/cfgas_stringformatter_unittest.cpp
+++ b/xfa/fgas/crt/cfgas_stringformatter_unittest.cpp
@@ -189,7 +189,9 @@
L"At 10:30 GMT on Jul 16, 1999"},
{L"en", L"1999-07-16T10:30Z",
L"time{'At 'HH:MM Z}date{' on 'MMM DD, YYYY}",
- L"At 10:30 GMT on Jul 16, 1999"}};
+ L"At 10:30 GMT on Jul 16, 1999"},
+ {L"en", L"9111T1111:", L"MMM D, YYYYTh:MM:SS A",
+ L"Jan 1, 9111 11:11:00 AM"}};
for (size_t i = 0; i < FX_ArraySize(tests); ++i) {
WideString result;