summaryrefslogtreecommitdiff
path: root/core/fpdfapi/edit
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-11-14 15:03:55 -0800
committerCommit bot <commit-bot@chromium.org>2016-11-14 15:03:55 -0800
commit137a344ad02056107e2e01d5d55f5e97d21fa74b (patch)
tree25bb148e669379d6f7f0d2d737d532db10ce9380 /core/fpdfapi/edit
parent88d87c13c25fbd20fd2963e8ff4b383c5d64b5f4 (diff)
downloadpdfium-137a344ad02056107e2e01d5d55f5e97d21fa74b.tar.xz
Make CPDF_PageContentGenerator methods take object numbers
This patch fixes a possibility that an owned CPDF_Stream is handed to the indirect object holder inside RealizeResource(). Its arguments are changed to take an object number, as is done elsewhere in the code, to suggest that only indirect objects are acceptable. BUG=660756 Review-Url: https://codereview.chromium.org/2489423002
Diffstat (limited to 'core/fpdfapi/edit')
-rw-r--r--core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp26
-rw-r--r--core/fpdfapi/edit/cpdf_pagecontentgenerator.h2
2 files changed, 17 insertions, 11 deletions
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
index 20b4ea6eaf..c27ca044e6 100644
--- a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
+++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
@@ -59,8 +59,9 @@ void CPDF_PageContentGenerator::GenerateContent() {
}
CFX_ByteString CPDF_PageContentGenerator::RealizeResource(
- CPDF_Object* pResourceObj,
+ uint32_t dwResourceObjNum,
const CFX_ByteString& bsType) {
+ ASSERT(dwResourceObjNum);
if (!m_pPage->m_pResources) {
m_pPage->m_pResources =
new CPDF_Dictionary(m_pDocument->GetByteStringPool());
@@ -82,8 +83,7 @@ CFX_ByteString CPDF_PageContentGenerator::RealizeResource(
}
idnum++;
}
- pResList->SetReferenceFor(name, m_pDocument,
- m_pDocument->AddIndirectObject(pResourceObj));
+ pResList->SetReferenceFor(name, m_pDocument, dwResourceObjNum);
return name;
}
@@ -104,9 +104,13 @@ void CPDF_PageContentGenerator::ProcessImage(CFX_ByteTextBuf& buf,
return;
bool bWasInline = pStream->IsInline();
- CFX_ByteString name = RealizeResource(pStream, "XObject");
if (bWasInline)
- pImageObj->SetUnownedImage(m_pDocument->GetPageData()->GetImage(pStream));
+ pImage->ConvertStreamToIndirectObject();
+
+ uint32_t dwObjNum = pStream->GetObjNum();
+ CFX_ByteString name = RealizeResource(dwObjNum, "XObject");
+ if (bWasInline)
+ pImageObj->SetUnownedImage(m_pDocument->GetPageData()->GetImage(dwObjNum));
buf << "/" << PDF_NameEncode(name) << " Do Q\n";
}
@@ -118,20 +122,22 @@ void CPDF_PageContentGenerator::ProcessForm(CFX_ByteTextBuf& buf,
if (!data || !size)
return;
+ buf << "q " << matrix << " cm ";
+
+ CFX_FloatRect bbox = m_pPage->GetPageBBox();
+ matrix.TransformRect(bbox);
+
CPDF_Dictionary* pFormDict =
new CPDF_Dictionary(m_pDocument->GetByteStringPool());
pFormDict->SetNameFor("Type", "XObject");
pFormDict->SetNameFor("Subtype", "Form");
-
- CFX_FloatRect bbox = m_pPage->GetPageBBox();
- matrix.TransformRect(bbox);
pFormDict->SetRectFor("BBox", bbox);
CPDF_Stream* pStream = new CPDF_Stream;
pStream->InitStream(data, size, pFormDict);
- buf << "q " << matrix << " cm ";
- CFX_ByteString name = RealizeResource(pStream, "XObject");
+ CFX_ByteString name =
+ RealizeResource(m_pDocument->AddIndirectObject(pStream), "XObject");
buf << "/" << PDF_NameEncode(name) << " Do Q\n";
}
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator.h b/core/fpdfapi/edit/cpdf_pagecontentgenerator.h
index ce605f0dfe..df8d3b0f8e 100644
--- a/core/fpdfapi/edit/cpdf_pagecontentgenerator.h
+++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator.h
@@ -34,7 +34,7 @@ class CPDF_PageContentGenerator {
const uint8_t* data,
uint32_t size,
CFX_Matrix& matrix);
- CFX_ByteString RealizeResource(CPDF_Object* pResourceObj,
+ CFX_ByteString RealizeResource(uint32_t dwResourceObjNum,
const CFX_ByteString& bsType);
CPDF_Page* m_pPage;