summaryrefslogtreecommitdiff
path: root/core/fpdfapi/page/cpdf_image.cpp
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/page/cpdf_image.cpp
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/page/cpdf_image.cpp')
-rw-r--r--core/fpdfapi/page/cpdf_image.cpp27
1 files changed, 16 insertions, 11 deletions
diff --git a/core/fpdfapi/page/cpdf_image.cpp b/core/fpdfapi/page/cpdf_image.cpp
index 976d6d8c47..4048c9bb4e 100644
--- a/core/fpdfapi/page/cpdf_image.cpp
+++ b/core/fpdfapi/page/cpdf_image.cpp
@@ -30,9 +30,6 @@ CPDF_Image::CPDF_Image(CPDF_Document* pDoc,
: m_pDocument(pDoc),
m_pStream(pStream.get()),
m_pOwnedStream(std::move(pStream)) {
- if (!m_pStream)
- return;
-
m_pOwnedDict =
ToDictionary(std::unique_ptr<CPDF_Object>(m_pStream->GetDict()->Clone()));
m_pDict = m_pOwnedDict.get();
@@ -42,9 +39,6 @@ CPDF_Image::CPDF_Image(CPDF_Document* pDoc,
CPDF_Image::CPDF_Image(CPDF_Document* pDoc, uint32_t dwStreamObjNum)
: m_pDocument(pDoc),
m_pStream(ToStream(pDoc->GetIndirectObject(dwStreamObjNum))) {
- if (!m_pStream)
- return;
-
m_pDict = m_pStream->GetDict();
FinishInitialization();
}
@@ -79,6 +73,14 @@ CPDF_Image* CPDF_Image::Clone() {
return pImage;
}
+void CPDF_Image::ConvertStreamToIndirectObject() {
+ if (!m_pStream->IsInline())
+ return;
+
+ ASSERT(m_pOwnedStream);
+ m_pDocument->AddIndirectObject(m_pOwnedStream.release());
+}
+
CPDF_Dictionary* CPDF_Image::InitJPEG(uint8_t* pData, uint32_t size) {
int32_t width;
int32_t height;
@@ -122,8 +124,10 @@ CPDF_Dictionary* CPDF_Image::InitJPEG(uint8_t* pData, uint32_t size) {
m_bIsMask = false;
m_Width = width;
m_Height = height;
- if (!m_pStream)
- m_pStream = new CPDF_Stream;
+ if (!m_pStream) {
+ m_pOwnedStream = pdfium::MakeUnique<CPDF_Stream>();
+ m_pStream = m_pOwnedStream.get();
+ }
return pDict;
}
@@ -334,9 +338,10 @@ void CPDF_Image::SetImage(const CFX_DIBitmap* pBitmap, int32_t iCompress) {
dest_offset = 0;
}
}
- if (!m_pStream)
- m_pStream = new CPDF_Stream;
-
+ if (!m_pStream) {
+ m_pOwnedStream = pdfium::MakeUnique<CPDF_Stream>();
+ m_pStream = m_pOwnedStream.get();
+ }
m_pStream->InitStream(dest_buf, dest_size, pDict);
m_bIsMask = pBitmap->IsAlphaMask();
m_Width = BitmapWidth;