From 430ab8363e77c48b2c2435af4d289f85e2be1b96 Mon Sep 17 00:00:00 2001 From: tsepez Date: Fri, 18 Nov 2016 14:48:21 -0800 Subject: Add unit test for CXFA_FileRead. The FileRead's return convention is being modified at https://codereview.chromium.org/2430743003/, so first provide a test of the old behaviour. Fix some issues with null dictionaries as provided by the CPDF_Stream default ctor along the way. Review-Url: https://codereview.chromium.org/2517513003 --- core/fpdfapi/parser/cpdf_stream.cpp | 4 ++++ core/fpdfapi/parser/cpdf_stream.h | 1 + core/fpdfapi/parser/cpdf_stream_acc.cpp | 20 ++++++++------------ 3 files changed, 13 insertions(+), 12 deletions(-) (limited to 'core/fpdfapi/parser') diff --git a/core/fpdfapi/parser/cpdf_stream.cpp b/core/fpdfapi/parser/cpdf_stream.cpp index e8ee022940..64261b14d3 100644 --- a/core/fpdfapi/parser/cpdf_stream.cpp +++ b/core/fpdfapi/parser/cpdf_stream.cpp @@ -113,6 +113,10 @@ bool CPDF_Stream::ReadRawData(FX_FILESIZE offset, return true; } +bool CPDF_Stream::HasFilter() const { + return m_pDict && m_pDict->KeyExist("Filter"); +} + CFX_WideString CPDF_Stream::GetUnicodeText() const { CPDF_StreamAcc stream; stream.LoadAllData(this, false); diff --git a/core/fpdfapi/parser/cpdf_stream.h b/core/fpdfapi/parser/cpdf_stream.h index ddf7cc5b69..c4f9aacf2b 100644 --- a/core/fpdfapi/parser/cpdf_stream.h +++ b/core/fpdfapi/parser/cpdf_stream.h @@ -46,6 +46,7 @@ class CPDF_Stream : public CPDF_Object { uint32_t buf_size) const; bool IsMemoryBased() const { return m_bMemoryBased; } + bool HasFilter() const; protected: std::unique_ptr CloneNonCyclic( diff --git a/core/fpdfapi/parser/cpdf_stream_acc.cpp b/core/fpdfapi/parser/cpdf_stream_acc.cpp index 81439bc677..01d8e148df 100644 --- a/core/fpdfapi/parser/cpdf_stream_acc.cpp +++ b/core/fpdfapi/parser/cpdf_stream_acc.cpp @@ -24,17 +24,16 @@ void CPDF_StreamAcc::LoadAllData(const CPDF_Stream* pStream, return; m_pStream = pStream; - if (pStream->IsMemoryBased() && - (!pStream->GetDict()->KeyExist("Filter") || bRawAccess)) { + if (pStream->IsMemoryBased() && (!pStream->HasFilter() || bRawAccess)) { m_dwSize = pStream->GetRawSize(); m_pData = pStream->GetRawData(); return; } - uint8_t* pSrcData; uint32_t dwSrcSize = pStream->GetRawSize(); if (dwSrcSize == 0) return; + uint8_t* pSrcData; if (!pStream->IsMemoryBased()) { pSrcData = m_pSrcData = FX_Alloc(uint8_t, dwSrcSize); if (!pStream->ReadRawData(0, pSrcData, dwSrcSize)) @@ -42,17 +41,14 @@ void CPDF_StreamAcc::LoadAllData(const CPDF_Stream* pStream, } else { pSrcData = pStream->GetRawData(); } - if (!pStream->GetDict()->KeyExist("Filter") || bRawAccess) { + if (!pStream->HasFilter() || bRawAccess) { + m_pData = pSrcData; + m_dwSize = dwSrcSize; + } else if (!PDF_DataDecode(pSrcData, dwSrcSize, m_pStream->GetDict(), m_pData, + m_dwSize, m_ImageDecoder, m_pImageParam, + estimated_size, bImageAcc)) { m_pData = pSrcData; m_dwSize = dwSrcSize; - } else { - bool bRet = PDF_DataDecode(pSrcData, dwSrcSize, m_pStream->GetDict(), - m_pData, m_dwSize, m_ImageDecoder, m_pImageParam, - estimated_size, bImageAcc); - if (!bRet) { - m_pData = pSrcData; - m_dwSize = dwSrcSize; - } } if (pSrcData != pStream->GetRawData() && pSrcData != m_pData) FX_Free(pSrcData); -- cgit v1.2.3