| OLD | NEW |
| 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 "public/fpdfview.h" | 7 #include "public/fpdfview.h" |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 1031 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1042 DLLEXPORT FPDF_DWORD STDCALL FPDF_CountNamedDests(FPDF_DOCUMENT document) { | 1042 DLLEXPORT FPDF_DWORD STDCALL FPDF_CountNamedDests(FPDF_DOCUMENT document) { |
| 1043 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); | 1043 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 1044 if (!pDoc) | 1044 if (!pDoc) |
| 1045 return 0; | 1045 return 0; |
| 1046 | 1046 |
| 1047 CPDF_Dictionary* pRoot = pDoc->GetRoot(); | 1047 CPDF_Dictionary* pRoot = pDoc->GetRoot(); |
| 1048 if (!pRoot) | 1048 if (!pRoot) |
| 1049 return 0; | 1049 return 0; |
| 1050 | 1050 |
| 1051 CPDF_NameTree nameTree(pDoc, "Dests"); | 1051 CPDF_NameTree nameTree(pDoc, "Dests"); |
| 1052 int count = nameTree.GetCount(); | 1052 pdfium::base::CheckedNumeric<FPDF_DWORD> count = nameTree.GetCount(); |
| 1053 CPDF_Dictionary* pDest = pRoot->GetDict("Dests"); | 1053 CPDF_Dictionary* pDest = pRoot->GetDict("Dests"); |
| 1054 if (pDest) | 1054 if (pDest) |
| 1055 count += pDest->GetCount(); | 1055 count += pDest->GetCount(); |
| 1056 return count; | 1056 |
| 1057 if (!count.IsValid()) |
| 1058 return 0; |
| 1059 |
| 1060 return count.ValueOrDie(); |
| 1057 } | 1061 } |
| 1058 | 1062 |
| 1059 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDestByName(FPDF_DOCUMENT document, | 1063 DLLEXPORT FPDF_DEST STDCALL FPDF_GetNamedDestByName(FPDF_DOCUMENT document, |
| 1060 FPDF_BYTESTRING name) { | 1064 FPDF_BYTESTRING name) { |
| 1061 if (!name || name[0] == 0) | 1065 if (!name || name[0] == 0) |
| 1062 return nullptr; | 1066 return nullptr; |
| 1063 | 1067 |
| 1064 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); | 1068 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 1065 if (!pDoc) | 1069 if (!pDoc) |
| 1066 return nullptr; | 1070 return nullptr; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1134 return nullptr; | 1138 return nullptr; |
| 1135 | 1139 |
| 1136 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); | 1140 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); |
| 1137 if (!pDoc) | 1141 if (!pDoc) |
| 1138 return nullptr; | 1142 return nullptr; |
| 1139 | 1143 |
| 1140 CPDF_Dictionary* pRoot = pDoc->GetRoot(); | 1144 CPDF_Dictionary* pRoot = pDoc->GetRoot(); |
| 1141 if (!pRoot) | 1145 if (!pRoot) |
| 1142 return nullptr; | 1146 return nullptr; |
| 1143 | 1147 |
| 1144 CPDF_Object* pDestObj = NULL; | 1148 CPDF_Object* pDestObj = nullptr; |
| 1145 CFX_ByteString bsName; | 1149 CFX_ByteString bsName; |
| 1146 CPDF_NameTree nameTree(pDoc, "Dests"); | 1150 CPDF_NameTree nameTree(pDoc, "Dests"); |
| 1147 int count = nameTree.GetCount(); | 1151 int count = nameTree.GetCount(); |
| 1148 if (index >= count) { | 1152 if (index >= count) { |
| 1149 CPDF_Dictionary* pDest = pRoot->GetDict("Dests"); | 1153 CPDF_Dictionary* pDest = pRoot->GetDict("Dests"); |
| 1150 if (!pDest) | 1154 if (!pDest) |
| 1151 return NULL; | 1155 return nullptr; |
| 1152 if (index >= count + pDest->GetCount()) | 1156 |
| 1153 return NULL; | 1157 pdfium::base::CheckedNumeric<int> checked_count = count; |
| 1158 checked_count += pDest->GetCount(); |
| 1159 if (!checked_count.IsValid() || index >= checked_count.ValueOrDie()) |
| 1160 return nullptr; |
| 1161 |
| 1154 index -= count; | 1162 index -= count; |
| 1155 FX_POSITION pos = pDest->GetStartPos(); | |
| 1156 int i = 0; | 1163 int i = 0; |
| 1157 while (pos) { | 1164 for (const auto& it : *pDest) { |
| 1158 pDestObj = pDest->GetNextElement(pos, bsName); | 1165 bsName = it.first; |
| 1166 pDestObj = it.second; |
| 1159 if (!pDestObj) | 1167 if (!pDestObj) |
| 1160 continue; | 1168 continue; |
| 1161 if (i == index) | 1169 if (i == index) |
| 1162 break; | 1170 break; |
| 1163 i++; | 1171 i++; |
| 1164 } | 1172 } |
| 1165 } else { | 1173 } else { |
| 1166 pDestObj = nameTree.LookupValue(index, bsName); | 1174 pDestObj = nameTree.LookupValue(index, bsName); |
| 1167 } | 1175 } |
| 1168 if (!pDestObj) | 1176 if (!pDestObj) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1181 if (!buffer) { | 1189 if (!buffer) { |
| 1182 *buflen = len; | 1190 *buflen = len; |
| 1183 } else if (*buflen >= len) { | 1191 } else if (*buflen >= len) { |
| 1184 memcpy(buffer, utf16Name.c_str(), len); | 1192 memcpy(buffer, utf16Name.c_str(), len); |
| 1185 *buflen = len; | 1193 *buflen = len; |
| 1186 } else { | 1194 } else { |
| 1187 *buflen = -1; | 1195 *buflen = -1; |
| 1188 } | 1196 } |
| 1189 return (FPDF_DEST)pDestObj; | 1197 return (FPDF_DEST)pDestObj; |
| 1190 } | 1198 } |
| OLD | NEW |