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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "../../include/javascript/JavaScript.h" 7 #include "../../include/javascript/JavaScript.h"
8 #include "../../include/javascript/IJavaScript.h" 8 #include "../../include/javascript/IJavaScript.h"
9 #include "../../include/javascript/JS_Define.h" 9 #include "../../include/javascript/JS_Define.h"
10 #include "../../include/javascript/JS_Object.h" 10 #include "../../include/javascript/JS_Object.h"
(...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 CFX_WideString sRet = L"",sPart = L""; 917 CFX_WideString sRet = L"",sPart = L"";
918 918
919 int nYear = JS_GetYearFromTime(dDate); 919 int nYear = JS_GetYearFromTime(dDate);
920 int nMonth = JS_GetMonthFromTime(dDate) + 1; 920 int nMonth = JS_GetMonthFromTime(dDate) + 1;
921 int nDay = JS_GetDayFromTime(dDate); 921 int nDay = JS_GetDayFromTime(dDate);
922 int nHour = JS_GetHourFromTime(dDate); 922 int nHour = JS_GetHourFromTime(dDate);
923 int nMin = JS_GetMinFromTime(dDate); 923 int nMin = JS_GetMinFromTime(dDate);
924 int nSec = JS_GetSecFromTime(dDate); 924 int nSec = JS_GetSecFromTime(dDate);
925 925
926 int i = 0; 926 int i = 0;
927 FX_WCHAR c;
928 while (i < format.GetLength()) 927 while (i < format.GetLength())
929 { 928 {
930 » » c = format.GetAt(i); 929 » FX_WCHAR c = format.GetAt(i);
930 int remaining = format.GetLength() - i - 1;
931 sPart = L""; 931 sPart = L"";
932 switch (c) 932 switch (c)
933 { 933 {
934 case 'y': 934 case 'y':
935 case 'm': 935 case 'm':
936 case 'd': 936 case 'd':
937 case 'H': 937 case 'H':
938 case 'h': 938 case 'h':
939 case 'M': 939 case 'M':
940 case 's': 940 case 's':
941 case 't': 941 case 't':
942 » » » » if (format.GetAt(i+1) != c) 942 » » » » if (remaining == 0 || format.GetAt(i+1) != c)
943 { 943 {
944 switch (c) 944 switch (c)
945 { 945 {
946 case 'y': 946 case 'y':
947 sPart += c; 947 sPart += c;
948 break; 948 break;
949 case 'm': 949 case 'm':
950 sPart.Format((FX_LPCWSTR )L"%d",nMonth); 950 sPart.Format((FX_LPCWSTR )L"%d",nMonth);
951 break; 951 break;
952 case 'd': 952 case 'd':
953 sPart.Format((FX_LPCWSTR )L"%d",nDay); 953 sPart.Format((FX_LPCWSTR )L"%d",nDay);
954 break; 954 break;
955 case 'H': 955 case 'H':
956 sPart.Format((FX_LPCWSTR )L"%d",nHour); 956 sPart.Format((FX_LPCWSTR )L"%d",nHour);
957 break; 957 break;
958 case 'h': 958 case 'h':
959 sPart.Format((FX_LPCWSTR )L"%d",nHour>12?nHour - 12:nHour); 959 sPart.Format((FX_LPCWSTR )L"%d",nHour>12?nHour - 12:nHour);
960 break; 960 break;
961 case 'M': 961 case 'M':
962 sPart.Format((FX_LPCWSTR )L"%d",nMin); 962 sPart.Format((FX_LPCWSTR )L"%d",nMin);
963 break; 963 break;
964 case 's': 964 case 's':
965 sPart.Format((FX_LPCWSTR )L"%d",nSec); 965 sPart.Format((FX_LPCWSTR )L"%d",nSec);
966 break; 966 break;
967 » » » » » » case 't':» » » » 967 » » » » » » case 't':
968 sPart += nHour>12?'p':'a '; 968 sPart += nHour>12?'p':'a ';
969 break; 969 break;
970 » » » » » }» » » » » 970 » » » » » }
971 i++; 971 i++;
972 } 972 }
973 » » » » else if (format.GetAt(i+1) == c && format.GetAt( i+2) != c) 973 » » » » else if (remaining == 1 || format.GetAt(i+2) != c)
974 { 974 {
975 switch (c) 975 switch (c)
976 { 976 {
977 case 'y': 977 case 'y':
978 sPart.Format((FX_LPCWSTR )L"%02d",nYear - (nYear / 100) * 100); 978 sPart.Format((FX_LPCWSTR )L"%02d",nYear - (nYear / 100) * 100);
979 break; 979 break;
980 case 'm': 980 case 'm':
981 sPart.Format((FX_LPCWSTR )L"%02d",nMonth); 981 sPart.Format((FX_LPCWSTR )L"%02d",nMonth);
982 break; 982 break;
983 case 'd': 983 case 'd':
984 sPart.Format((FX_LPCWSTR )L"%02d",nDay); 984 sPart.Format((FX_LPCWSTR )L"%02d",nDay);
985 break; 985 break;
986 case 'H': 986 case 'H':
987 sPart.Format((FX_LPCWSTR )L"%02d",nHour); 987 sPart.Format((FX_LPCWSTR )L"%02d",nHour);
988 break; 988 break;
989 case 'h': 989 case 'h':
990 sPart.Format((FX_LPCWSTR )L"%02d",nHour>12?nHour - 12:nHour); 990 sPart.Format((FX_LPCWSTR )L"%02d",nHour>12?nHour - 12:nHour);
991 break; 991 break;
992 case 'M': 992 case 'M':
993 sPart.Format((FX_LPCWSTR )L"%02d",nMin); 993 sPart.Format((FX_LPCWSTR )L"%02d",nMin);
994 break; 994 break;
995 case 's': 995 case 's':
996 sPart.Format((FX_LPCWSTR )L"%02d",nSec); 996 sPart.Format((FX_LPCWSTR )L"%02d",nSec);
997 break; 997 break;
998 » » » » » » case 't':» » » » » » » 998 » » » » » » case 't':
999 sPart = nHour>12? (FX_LP CWSTR)L"pm": (FX_LPCWSTR)L"am"; 999 sPart = nHour>12? (FX_LP CWSTR)L"pm": (FX_LPCWSTR)L"am";
1000 break; 1000 break;
1001 » » » » » }» » » 1001 » » » » » }
1002 i+=2; 1002 i+=2;
1003 } 1003 }
1004 » » » » else if (format.GetAt(i+1) == c && format.GetAt( i+2) == c && format.GetAt(i+3) != c) 1004 » » » » else if (remaining == 2 || format.GetAt(i+3) != c)
1005 » » » » {» » 1005 » » » » {
1006 switch (c) 1006 switch (c)
1007 { 1007 {
1008 case 'm': 1008 case 'm':
1009 i+=3; 1009 i+=3;
1010 if (nMonth > 0&&nMonth < = 12) 1010 if (nMonth > 0&&nMonth < = 12)
1011 sPart += months[ nMonth - 1]; 1011 sPart += months[ nMonth - 1];
1012 break; 1012 break;
1013 default: 1013 default:
1014 i+=3; 1014 i+=3;
1015 sPart += c; 1015 sPart += c;
1016 sPart += c; 1016 sPart += c;
1017 sPart += c; 1017 sPart += c;
1018 break; 1018 break;
1019 » » » » » }» » » » » 1019 » » » » » }
1020 } 1020 }
1021 » » » » else if (format.GetAt(i+1) == c && format.GetAt( i+2) == c && format.GetAt(i+3) == c && format.GetAt(i+4) != c) 1021 » » » » else if (remaining == 3 || format.GetAt(i+4) != c)
1022 { 1022 {
1023 switch (c) 1023 switch (c)
1024 { 1024 {
1025 case 'y': 1025 case 'y':
1026 sPart.Format((FX_LPCWSTR )L"%04d",nYear); 1026 sPart.Format((FX_LPCWSTR )L"%04d",nYear);
1027 i += 4; 1027 i += 4;
1028 » » » » » » » break;» 1028 » » » » » » » break;
1029 case 'm': 1029 case 'm':
1030 i+=4; 1030 i+=4;
1031 if (nMonth > 0&&nMonth < = 12) 1031 if (nMonth > 0&&nMonth < = 12)
1032 sPart += fullmon ths[nMonth - 1]; 1032 sPart += fullmon ths[nMonth - 1];
1033 break; 1033 break;
1034 default: 1034 default:
1035 i += 4; 1035 i += 4;
1036 sPart += c; 1036 sPart += c;
1037 sPart += c; 1037 sPart += c;
1038 sPart += c; 1038 sPart += c;
1039 sPart += c; 1039 sPart += c;
1040 break; 1040 break;
1041 » » » » » }» » » » » 1041 » » » » » }
1042 } 1042 }
1043 else 1043 else
1044 { 1044 {
1045 i++; 1045 i++;
1046 sPart += c; 1046 sPart += c;
1047 } 1047 }
1048 » » » » break;» » » 1048 » » » » break;
1049 default: 1049 default:
1050 i++; 1050 i++;
1051 sPart += c; 1051 sPart += c;
1052 break; 1052 break;
1053 } 1053 }
1054 » » 1054
1055 sRet += sPart; 1055 sRet += sPart;
1056 } 1056 }
1057 1057
1058 return sRet; 1058 return sRet;
1059 } 1059 }
1060 1060
1061 /* -------------------------------------------------------------------------- */ 1061 /* -------------------------------------------------------------------------- */
1062 1062
1063 //function AFNumber_Format(nDec, sepStyle, negStyle, currStyle, strCurrency, bCu rrencyPrepend) 1063 //function AFNumber_Format(nDec, sepStyle, negStyle, currStyle, strCurrency, bCu rrencyPrepend)
1064 FX_BOOL CJS_PublicMethods::AFNumber_Format(OBJ_METHOD_PARAMS) 1064 FX_BOOL CJS_PublicMethods::AFNumber_Format(OBJ_METHOD_PARAMS)
(...skipping 1262 matching lines...) Expand 10 before | Expand all | Expand 10 after
2327 nums.SetElement(nIndex,CJS_Value(isolate,(FX_LPCWSTR)sPart)); 2327 nums.SetElement(nIndex,CJS_Value(isolate,(FX_LPCWSTR)sPart));
2328 } 2328 }
2329 2329
2330 if (nums.GetLength() > 0) 2330 if (nums.GetLength() > 0)
2331 vRet = nums; 2331 vRet = nums;
2332 else 2332 else
2333 vRet.SetNull(); 2333 vRet.SetNull();
2334 2334
2335 return TRUE; 2335 return TRUE;
2336 } 2336 }
OLDNEW
« 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