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

Unified Diff: core/fpdfdoc/cpdf_formfield.cpp

Issue 2271373003: Fix infinite loops in FPDF_GetFullName(). (Closed)
Patch Set: IWYU Created 4 years, 4 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 | « BUILD.gn ('k') | core/fpdfdoc/cpdf_formfield_unittest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fpdfdoc/cpdf_formfield.cpp
diff --git a/core/fpdfdoc/cpdf_formfield.cpp b/core/fpdfdoc/cpdf_formfield.cpp
index ac6c01bae25a839de40f523ac3af59f9932c1069..8d7d0b4dc02f923edb55454fa1efa431c4cc00c2 100644
--- a/core/fpdfdoc/cpdf_formfield.cpp
+++ b/core/fpdfdoc/cpdf_formfield.cpp
@@ -6,6 +6,8 @@
#include "core/fpdfdoc/include/cpdf_formfield.h"
+#include <set>
+
#include "core/fpdfapi/fpdf_parser/include/cfdf_document.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
@@ -16,6 +18,7 @@
#include "core/fpdfdoc/cpvt_generateap.h"
#include "core/fpdfdoc/include/cpdf_formcontrol.h"
#include "core/fpdfdoc/include/cpdf_interform.h"
+#include "third_party/base/stl_util.h"
namespace {
@@ -65,16 +68,20 @@ CPDF_Object* FPDF_GetFieldAttr(CPDF_Dictionary* pFieldDict,
CFX_WideString FPDF_GetFullName(CPDF_Dictionary* pFieldDict) {
CFX_WideString full_name;
+ std::set<CPDF_Dictionary*> visited;
CPDF_Dictionary* pLevel = pFieldDict;
while (pLevel) {
+ visited.insert(pLevel);
CFX_WideString short_name = pLevel->GetUnicodeTextBy("T");
- if (short_name != L"") {
- if (full_name == L"")
+ if (!short_name.IsEmpty()) {
+ if (full_name.IsEmpty())
full_name = short_name;
else
full_name = short_name + L"." + full_name;
}
pLevel = pLevel->GetDictBy("Parent");
+ if (pdfium::ContainsKey(visited, pLevel))
+ break;
}
return full_name;
}
@@ -679,8 +686,8 @@ int CPDF_FormField::InsertOption(CFX_WideString csOptLabel,
m_pDict->SetAt("Opt", pOpt);
}
- int iCount = (int)pOpt->GetCount();
- if (index < 0 || index >= iCount) {
+ int iCount = pdfium::base::checked_cast<int, size_t>(pOpt->GetCount());
+ if (index >= iCount) {
pOpt->AddString(csStr);
index = iCount;
} else {
« no previous file with comments | « BUILD.gn ('k') | core/fpdfdoc/cpdf_formfield_unittest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698