From 77d8ed02c7e97471ceccee5abbabeb2fdea413c7 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Tue, 30 Jan 2018 17:48:32 +0000 Subject: Revert "Use UnownedPtr instead of T* in MaybeOwned." This reverts commit e563e8352139e4852a955e319023b09f2844aee9. Reason for revert: Original change's description: > Use UnownedPtr instead of T* in MaybeOwned. > > Always check the liftime in the unowned case. Doing so unearthed > the following issues: > > Transient lifetime issue in jbig2_image when doing realloc(). > Stale (but unused) dictionary pointer in CPDF_Image. > Destruction order in error branch in cpdf_dibsource.cpp > > Change-Id: I12b758aafeefedc7abe1e8b21a18db959929e95f > Reviewed-on: https://pdfium-review.googlesource.com/24552 > Commit-Queue: Tom Sepez > Reviewed-by: dsinclair TBR=thestig@chromium.org,tsepez@chromium.org,dsinclair@chromium.org Change-Id: I3c56ee6ab502da90e3adb7507dbc8cc92f090140 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://pdfium-review.googlesource.com/24670 Reviewed-by: Tom Sepez Commit-Queue: Tom Sepez --- core/fpdfapi/page/cpdf_image.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'core/fpdfapi/page/cpdf_image.cpp') diff --git a/core/fpdfapi/page/cpdf_image.cpp b/core/fpdfapi/page/cpdf_image.cpp index 5f82886a9b..65ca78e08e 100644 --- a/core/fpdfapi/page/cpdf_image.cpp +++ b/core/fpdfapi/page/cpdf_image.cpp @@ -35,27 +35,33 @@ CPDF_Image::CPDF_Image(CPDF_Document* pDoc) : m_pDocument(pDoc) {} CPDF_Image::CPDF_Image(CPDF_Document* pDoc, std::unique_ptr pStream) - : m_bIsInline(true), m_pDocument(pDoc), m_pStream(std::move(pStream)) { + : m_bIsInline(true), + m_pDocument(pDoc), + m_pStream(std::move(pStream)), + m_pDict(ToDictionary(m_pStream->GetDict()->Clone())) { ASSERT(m_pStream.IsOwned()); - FinishInitialization(m_pStream->GetDict()); + ASSERT(m_pDict.IsOwned()); + FinishInitialization(); } CPDF_Image::CPDF_Image(CPDF_Document* pDoc, uint32_t dwStreamObjNum) : m_pDocument(pDoc), - m_pStream(ToStream(pDoc->GetIndirectObject(dwStreamObjNum))) { + m_pStream(ToStream(pDoc->GetIndirectObject(dwStreamObjNum))), + m_pDict(m_pStream->GetDict()) { ASSERT(!m_pStream.IsOwned()); - FinishInitialization(m_pStream->GetDict()); + ASSERT(!m_pDict.IsOwned()); + FinishInitialization(); } CPDF_Image::~CPDF_Image() {} -void CPDF_Image::FinishInitialization(CPDF_Dictionary* pDict) { - m_pOC = pDict->GetDictFor("OC"); +void CPDF_Image::FinishInitialization() { + m_pOC = m_pDict->GetDictFor("OC"); m_bIsMask = - !pDict->KeyExist("ColorSpace") || pDict->GetIntegerFor("ImageMask"); - m_bInterpolate = !!pDict->GetIntegerFor("Interpolate"); - m_Height = pDict->GetIntegerFor("Height"); - m_Width = pDict->GetIntegerFor("Width"); + !m_pDict->KeyExist("ColorSpace") || m_pDict->GetIntegerFor("ImageMask"); + m_bInterpolate = !!m_pDict->GetIntegerFor("Interpolate"); + m_Height = m_pDict->GetIntegerFor("Height"); + m_Width = m_pDict->GetIntegerFor("Width"); } void CPDF_Image::ConvertStreamToIndirectObject() { -- cgit v1.2.3