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

Unified Diff: core/fpdfapi/fpdf_parser/cpdf_stream.cpp

Issue 2250533002: Fix stack overflow in object Clone() functions (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: rebase again 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 | « core/fpdfapi/fpdf_parser/cpdf_reference.cpp ('k') | core/fpdfapi/fpdf_parser/cpdf_string.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fpdfapi/fpdf_parser/cpdf_stream.cpp
diff --git a/core/fpdfapi/fpdf_parser/cpdf_stream.cpp b/core/fpdfapi/fpdf_parser/cpdf_stream.cpp
index 7e65c25533b76228e5911a9d376fbbb0caf8e8b0..58b9767dfbc4dfe46dd755a83b8816e91abc80c3 100644
--- a/core/fpdfapi/fpdf_parser/cpdf_stream.cpp
+++ b/core/fpdfapi/fpdf_parser/cpdf_stream.cpp
@@ -9,6 +9,7 @@
#include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
#include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h"
#include "core/fpdfapi/fpdf_parser/include/fpdf_parser_decode.h"
+#include "third_party/base/stl_util.h"
CPDF_Stream::CPDF_Stream(uint8_t* pData, uint32_t size, CPDF_Dictionary* pDict)
: m_pDict(pDict),
@@ -17,6 +18,7 @@ CPDF_Stream::CPDF_Stream(uint8_t* pData, uint32_t size, CPDF_Dictionary* pDict)
m_pDataBuf(pData) {}
CPDF_Stream::~CPDF_Stream() {
+ m_ObjNum = kInvalidObjNum;
if (IsMemoryBased())
FX_Free(m_pDataBuf);
@@ -71,13 +73,22 @@ void CPDF_Stream::InitStream(const uint8_t* pData,
m_pDict->SetAtInteger("Length", size);
}
-CPDF_Object* CPDF_Stream::Clone(FX_BOOL bDirect) const {
+CPDF_Object* CPDF_Stream::Clone() const {
+ return CloneObjectNonCyclic(false);
+}
+
+CPDF_Object* CPDF_Stream::CloneNonCyclic(
+ bool bDirect,
+ std::set<const CPDF_Object*>* pVisited) const {
+ pVisited->insert(this);
CPDF_StreamAcc acc;
acc.LoadAllData(this, TRUE);
uint32_t streamSize = acc.GetSize();
CPDF_Dictionary* pDict = GetDict();
- if (pDict)
- pDict = ToDictionary(pDict->Clone(bDirect));
+ if (pDict && !pdfium::ContainsKey(*pVisited, pDict)) {
+ pDict = ToDictionary(
+ static_cast<CPDF_Object*>(pDict)->CloneNonCyclic(bDirect, pVisited));
+ }
return new CPDF_Stream(acc.DetachData(), streamSize, pDict);
}
« no previous file with comments | « core/fpdfapi/fpdf_parser/cpdf_reference.cpp ('k') | core/fpdfapi/fpdf_parser/cpdf_string.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698