Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2273)

Unified Diff: fpdfsdk/src/javascript/PublicMethods.cpp

Issue 407243003: Fix lookahead beyond bounds in CJS_PublicMethods::MakeFormatDate(). (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Tidy a bit, Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fpdfsdk/src/javascript/PublicMethods.cpp
diff --git a/fpdfsdk/src/javascript/PublicMethods.cpp b/fpdfsdk/src/javascript/PublicMethods.cpp
index 55228687bcf86bb394b1e0efcee917fb48044501..08d5cb707ce3a52733b0ba275284c6ab47f649d9 100644
--- a/fpdfsdk/src/javascript/PublicMethods.cpp
+++ b/fpdfsdk/src/javascript/PublicMethods.cpp
@@ -924,10 +924,10 @@ CFX_WideString CJS_PublicMethods::MakeFormatDate(double dDate, const CFX_WideStr
int nSec = JS_GetSecFromTime(dDate);
int i = 0;
- FX_WCHAR c;
while (i < format.GetLength())
{
- c = format.GetAt(i);
+ FX_WCHAR c = format.GetAt(i);
+ int remaining = format.GetLength() - i - 1;
sPart = L"";
switch (c)
{
@@ -939,7 +939,7 @@ CFX_WideString CJS_PublicMethods::MakeFormatDate(double dDate, const CFX_WideStr
case 'M':
case 's':
case 't':
- if (format.GetAt(i+1) != c)
+ if (remaining == 0 || format.GetAt(i+1) != c)
{
switch (c)
{
@@ -964,13 +964,13 @@ CFX_WideString CJS_PublicMethods::MakeFormatDate(double dDate, const CFX_WideStr
case 's':
sPart.Format((FX_LPCWSTR)L"%d",nSec);
break;
- case 't':
+ case 't':
sPart += nHour>12?'p':'a';
break;
- }
+ }
i++;
}
- else if (format.GetAt(i+1) == c && format.GetAt(i+2) != c)
+ else if (remaining == 1 || format.GetAt(i+2) != c)
{
switch (c)
{
@@ -995,14 +995,14 @@ CFX_WideString CJS_PublicMethods::MakeFormatDate(double dDate, const CFX_WideStr
case 's':
sPart.Format((FX_LPCWSTR)L"%02d",nSec);
break;
- case 't':
+ case 't':
sPart = nHour>12? (FX_LPCWSTR)L"pm": (FX_LPCWSTR)L"am";
break;
- }
+ }
i+=2;
}
- else if (format.GetAt(i+1) == c && format.GetAt(i+2) == c && format.GetAt(i+3) != c)
- {
+ else if (remaining == 2 || format.GetAt(i+3) != c)
+ {
switch (c)
{
case 'm':
@@ -1016,16 +1016,16 @@ CFX_WideString CJS_PublicMethods::MakeFormatDate(double dDate, const CFX_WideStr
sPart += c;
sPart += c;
break;
- }
+ }
}
- else if (format.GetAt(i+1) == c && format.GetAt(i+2) == c && format.GetAt(i+3) == c && format.GetAt(i+4) != c)
+ else if (remaining == 3 || format.GetAt(i+4) != c)
{
switch (c)
{
case 'y':
sPart.Format((FX_LPCWSTR)L"%04d",nYear);
i += 4;
- break;
+ break;
case 'm':
i+=4;
if (nMonth > 0&&nMonth <= 12)
@@ -1038,20 +1038,20 @@ CFX_WideString CJS_PublicMethods::MakeFormatDate(double dDate, const CFX_WideStr
sPart += c;
sPart += c;
break;
- }
+ }
}
else
{
i++;
sPart += c;
}
- break;
+ break;
default:
i++;
sPart += c;
break;
}
-
+
sRet += sPart;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698