summaryrefslogtreecommitdiff
path: root/core/fpdfapi
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfapi')
-rw-r--r--core/fpdfapi/page/cpdf_contentparser.cpp19
-rw-r--r--core/fpdfapi/page/cpdf_contentparser.h3
-rw-r--r--core/fpdfapi/parser/cpdf_stream_acc.cpp14
-rw-r--r--core/fpdfapi/parser/cpdf_stream_acc.h4
4 files changed, 25 insertions, 15 deletions
diff --git a/core/fpdfapi/page/cpdf_contentparser.cpp b/core/fpdfapi/page/cpdf_contentparser.cpp
index 0571405908..30701422d2 100644
--- a/core/fpdfapi/page/cpdf_contentparser.cpp
+++ b/core/fpdfapi/page/cpdf_contentparser.cpp
@@ -103,15 +103,11 @@ CPDF_ContentParser::CPDF_ContentParser(CPDF_Form* pForm,
m_pSingleStream =
pdfium::MakeRetain<CPDF_StreamAcc>(pForm->m_pFormStream.Get());
m_pSingleStream->LoadAllData(false);
- m_pData = const_cast<uint8_t*>(m_pSingleStream->GetData());
+ m_pData.Reset(m_pSingleStream->GetData());
m_Size = m_pSingleStream->GetSize();
}
-CPDF_ContentParser::~CPDF_ContentParser() {
- // TODO(thestig): Switch |m_pData| to MaybeOwned?
- if (!m_pSingleStream)
- FX_Free(m_pData);
-}
+CPDF_ContentParser::~CPDF_ContentParser() {}
bool CPDF_ContentParser::Continue(IFX_PauseIndicator* pPause) {
if (m_bIsDone)
@@ -131,16 +127,17 @@ bool CPDF_ContentParser::Continue(IFX_PauseIndicator* pPause) {
return false;
}
m_Size = safeSize.ValueOrDie();
- m_pData = FX_Alloc(uint8_t, m_Size);
+ m_pData.Reset(std::unique_ptr<uint8_t, FxFreeDeleter>(
+ FX_Alloc(uint8_t, m_Size)));
uint32_t pos = 0;
for (const auto& stream : m_StreamArray) {
- memcpy(m_pData + pos, stream->GetData(), stream->GetSize());
+ memcpy(m_pData.Get() + pos, stream->GetData(), stream->GetSize());
pos += stream->GetSize();
- m_pData[pos++] = ' ';
+ m_pData.Get()[pos++] = ' ';
}
m_StreamArray.clear();
} else {
- m_pData = const_cast<uint8_t*>(m_pSingleStream->GetData());
+ m_pData.Reset(m_pSingleStream->GetData());
m_Size = m_pSingleStream->GetSize();
}
m_InternalStage = STAGE_PARSE;
@@ -170,7 +167,7 @@ bool CPDF_ContentParser::Continue(IFX_PauseIndicator* pPause) {
m_InternalStage = STAGE_CHECKCLIP;
} else {
m_CurrentOffset +=
- m_pParser->Parse(m_pData + m_CurrentOffset,
+ m_pParser->Parse(m_pData.Get() + m_CurrentOffset,
m_Size - m_CurrentOffset, PARSE_STEP_LIMIT);
}
}
diff --git a/core/fpdfapi/page/cpdf_contentparser.h b/core/fpdfapi/page/cpdf_contentparser.h
index c4fcb9060b..c65da6da55 100644
--- a/core/fpdfapi/page/cpdf_contentparser.h
+++ b/core/fpdfapi/page/cpdf_contentparser.h
@@ -14,6 +14,7 @@
#include "core/fpdfapi/page/cpdf_pageobjectholder.h"
#include "core/fpdfapi/page/cpdf_streamcontentparser.h"
#include "core/fpdfapi/parser/cpdf_stream_acc.h"
+#include "core/fxcrt/maybe_owned.h"
#include "core/fxcrt/unowned_ptr.h"
class CPDF_AllStates;
@@ -52,7 +53,7 @@ class CPDF_ContentParser {
uint32_t m_nStreams = 0;
RetainPtr<CPDF_StreamAcc> m_pSingleStream;
std::vector<RetainPtr<CPDF_StreamAcc>> m_StreamArray;
- uint8_t* m_pData = nullptr;
+ MaybeOwned<uint8_t, FxFreeDeleter> m_pData;
uint32_t m_Size = 0;
uint32_t m_CurrentOffset = 0;
diff --git a/core/fpdfapi/parser/cpdf_stream_acc.cpp b/core/fpdfapi/parser/cpdf_stream_acc.cpp
index ccc3fdae53..91d458f9a7 100644
--- a/core/fpdfapi/parser/cpdf_stream_acc.cpp
+++ b/core/fpdfapi/parser/cpdf_stream_acc.cpp
@@ -61,9 +61,11 @@ CPDF_StreamAcc::~CPDF_StreamAcc() {
}
const uint8_t* CPDF_StreamAcc::GetData() const {
- if (m_bNewBuf)
- return m_pData;
- return m_pStream ? m_pStream->GetRawData() : nullptr;
+ return GetDataHelper();
+}
+
+uint8_t* CPDF_StreamAcc::GetData() {
+ return GetDataHelper();
}
uint32_t CPDF_StreamAcc::GetSize() const {
@@ -83,3 +85,9 @@ std::unique_ptr<uint8_t, FxFreeDeleter> CPDF_StreamAcc::DetachData() {
memcpy(p.get(), m_pData, m_dwSize);
return p;
}
+
+uint8_t* CPDF_StreamAcc::GetDataHelper() const {
+ if (m_bNewBuf)
+ return m_pData;
+ return m_pStream ? m_pStream->GetRawData() : nullptr;
+}
diff --git a/core/fpdfapi/parser/cpdf_stream_acc.h b/core/fpdfapi/parser/cpdf_stream_acc.h
index a8a2540880..c270285345 100644
--- a/core/fpdfapi/parser/cpdf_stream_acc.h
+++ b/core/fpdfapi/parser/cpdf_stream_acc.h
@@ -33,6 +33,7 @@ class CPDF_StreamAcc : public Retainable {
}
const uint8_t* GetData() const;
+ uint8_t* GetData();
uint32_t GetSize() const;
const ByteString& GetImageDecoder() const { return m_ImageDecoder; }
const CPDF_Dictionary* GetImageParam() const { return m_pImageParam; }
@@ -42,6 +43,9 @@ class CPDF_StreamAcc : public Retainable {
explicit CPDF_StreamAcc(const CPDF_Stream* pStream);
~CPDF_StreamAcc() override;
+ private:
+ uint8_t* GetDataHelper() const;
+
uint8_t* m_pData;
uint32_t m_dwSize;
bool m_bNewBuf;