summaryrefslogtreecommitdiff
path: root/core/fpdfapi
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfapi')
-rw-r--r--core/fpdfapi/parser/cpdf_object_unittest.cpp19
-rw-r--r--core/fpdfapi/parser/cpdf_stream.h4
-rw-r--r--core/fpdfapi/parser/cpdf_stream_acc.cpp10
3 files changed, 19 insertions, 14 deletions
diff --git a/core/fpdfapi/parser/cpdf_object_unittest.cpp b/core/fpdfapi/parser/cpdf_object_unittest.cpp
index 4780e87bc0..856dd0ac3b 100644
--- a/core/fpdfapi/parser/cpdf_object_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_object_unittest.cpp
@@ -17,6 +17,7 @@
#include "core/fpdfapi/parser/cpdf_number.h"
#include "core/fpdfapi/parser/cpdf_reference.h"
#include "core/fpdfapi/parser/cpdf_stream.h"
+#include "core/fpdfapi/parser/cpdf_stream_acc.h"
#include "core/fpdfapi/parser/cpdf_string.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -153,16 +154,18 @@ class PDFObjectsTest : public testing::Test {
// Compare dictionaries.
if (!Equal(stream1->GetDict(), stream2->GetDict()))
return false;
+
+ auto streamAcc1 = pdfium::MakeRetain<CPDF_StreamAcc>(stream1);
+ streamAcc1->LoadAllDataRaw();
+ auto streamAcc2 = pdfium::MakeRetain<CPDF_StreamAcc>(stream2);
+ streamAcc2->LoadAllDataRaw();
+
// Compare sizes.
- if (stream1->GetRawSize() != stream2->GetRawSize())
+ if (streamAcc1->GetSize() != streamAcc2->GetSize())
return false;
- // Compare contents.
- // Since this function is used for testing Clone(), only memory based
- // streams need to be handled.
- if (!stream1->IsMemoryBased() || !stream2->IsMemoryBased())
- return false;
- return memcmp(stream1->GetRawData(), stream2->GetRawData(),
- stream1->GetRawSize()) == 0;
+
+ return memcmp(streamAcc1->GetData(), streamAcc2->GetData(),
+ streamAcc2->GetSize()) == 0;
}
case CPDF_Object::REFERENCE:
return obj1->AsReference()->GetRefObjNum() ==
diff --git a/core/fpdfapi/parser/cpdf_stream.h b/core/fpdfapi/parser/cpdf_stream.h
index cc3dcac227..7e98f300ba 100644
--- a/core/fpdfapi/parser/cpdf_stream.h
+++ b/core/fpdfapi/parser/cpdf_stream.h
@@ -37,7 +37,9 @@ class CPDF_Stream : public CPDF_Object {
bool WriteTo(IFX_ArchiveStream* archive) const override;
uint32_t GetRawSize() const { return m_dwSize; }
- uint8_t* GetRawData() const { return m_pDataBuf.get(); }
+ // Will be null in case when stream is not memory based.
+ // Use CPDF_StreamAcc to data access in all cases.
+ uint8_t* GetInMemoryRawData() const { return m_pDataBuf.get(); }
// Does not takes ownership of |pData|, copies into internally-owned buffer.
void SetData(const uint8_t* pData, uint32_t size);
diff --git a/core/fpdfapi/parser/cpdf_stream_acc.cpp b/core/fpdfapi/parser/cpdf_stream_acc.cpp
index 9cf9a1f464..1734b0ddcb 100644
--- a/core/fpdfapi/parser/cpdf_stream_acc.cpp
+++ b/core/fpdfapi/parser/cpdf_stream_acc.cpp
@@ -26,7 +26,7 @@ void CPDF_StreamAcc::LoadAllData(bool bRawAccess,
bool bProcessRawData = bRawAccess || !m_pStream->HasFilter();
if (bProcessRawData && m_pStream->IsMemoryBased()) {
m_dwSize = m_pStream->GetRawSize();
- m_pData = m_pStream->GetRawData();
+ m_pData = m_pStream->GetInMemoryRawData();
return;
}
uint32_t dwSrcSize = m_pStream->GetRawSize();
@@ -35,7 +35,7 @@ void CPDF_StreamAcc::LoadAllData(bool bRawAccess,
uint8_t* pSrcData;
if (m_pStream->IsMemoryBased()) {
- pSrcData = m_pStream->GetRawData();
+ pSrcData = m_pStream->GetInMemoryRawData();
} else {
pSrcData = m_pSrcData = FX_Alloc(uint8_t, dwSrcSize);
if (!m_pStream->ReadRawData(0, pSrcData, dwSrcSize))
@@ -50,10 +50,10 @@ void CPDF_StreamAcc::LoadAllData(bool bRawAccess,
m_pData = pSrcData;
m_dwSize = dwSrcSize;
}
- if (pSrcData != m_pStream->GetRawData() && pSrcData != m_pData)
+ if (pSrcData != m_pStream->GetInMemoryRawData() && pSrcData != m_pData)
FX_Free(pSrcData);
m_pSrcData = nullptr;
- m_bNewBuf = m_pData != m_pStream->GetRawData();
+ m_bNewBuf = m_pData != m_pStream->GetInMemoryRawData();
}
void CPDF_StreamAcc::LoadAllDataFiltered() {
@@ -71,7 +71,7 @@ const CPDF_Dictionary* CPDF_StreamAcc::GetDict() const {
uint8_t* CPDF_StreamAcc::GetData() const {
if (m_bNewBuf)
return m_pData;
- return m_pStream ? m_pStream->GetRawData() : nullptr;
+ return m_pStream ? m_pStream->GetInMemoryRawData() : nullptr;
}
uint32_t CPDF_StreamAcc::GetSize() const {