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/edit/fpdf_edit_create.cpp | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) (limited to 'core/fpdfapi/edit') diff --git a/core/fpdfapi/edit/fpdf_edit_create.cpp b/core/fpdfapi/edit/fpdf_edit_create.cpp index ff12606399..360472948d 100644 --- a/core/fpdfapi/edit/fpdf_edit_create.cpp +++ b/core/fpdfapi/edit/fpdf_edit_create.cpp @@ -417,26 +417,24 @@ CPDF_FlateEncoder::CPDF_FlateEncoder(CPDF_Stream* pStream, bool bFlateEncode) m_bCloned(false), m_bNewData(false) { m_Acc.LoadAllData(pStream, true); - if ((pStream && pStream->GetDict() && - pStream->GetDict()->KeyExist("Filter")) || - !bFlateEncode) { - if (pStream->GetDict()->KeyExist("Filter") && !bFlateEncode) { - CPDF_StreamAcc destAcc; - destAcc.LoadAllData(pStream); - m_dwSize = destAcc.GetSize(); - m_pData = (uint8_t*)destAcc.DetachData(); - m_pDict = ToDictionary(pStream->GetDict()->Clone().release()); - m_pDict->RemoveFor("Filter"); - m_bNewData = true; - m_bCloned = true; - } else { - m_pData = (uint8_t*)m_Acc.GetData(); - m_dwSize = m_Acc.GetSize(); - m_pDict = pStream->GetDict(); - } + bool bHasFilter = pStream && pStream->HasFilter(); + if (bHasFilter && !bFlateEncode) { + CPDF_StreamAcc destAcc; + destAcc.LoadAllData(pStream); + m_dwSize = destAcc.GetSize(); + m_pData = (uint8_t*)destAcc.DetachData(); + m_pDict = ToDictionary(pStream->GetDict()->Clone().release()); + m_pDict->RemoveFor("Filter"); + m_bNewData = true; + m_bCloned = true; + return; + } + if (bHasFilter || !bFlateEncode) { + m_pData = (uint8_t*)m_Acc.GetData(); + m_dwSize = m_Acc.GetSize(); + m_pDict = pStream->GetDict(); return; } - m_bNewData = true; m_bCloned = true; // TODO(thestig): Move to Init() and check return value. -- cgit v1.2.3