summaryrefslogtreecommitdiff
path: root/core/fpdfapi/page/cpdf_streamparser.cpp
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-04-06 23:48:24 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-06 23:48:24 +0000
commit6058efdbdc186e120e7e2121c290ac4d820ffbf8 (patch)
tree8944872de2d924d3efd76266cc929c6f25199134 /core/fpdfapi/page/cpdf_streamparser.cpp
parent2aa01f5ccbf1464b43527c1ffa6b42bafed9ebeb (diff)
downloadpdfium-6058efdbdc186e120e7e2121c290ac4d820ffbf8.tar.xz
Add span.h from chromium base.chromium/3392
Allows indexing with better bounds-checking to occur. Some small modifications are required to deal with PDFium being intentionally held at C++11 compliance, not C++14. Use in one place as check on correctness. Change-Id: Id2875cf0a93980112bc536a93c4f9ec5306c0dac Reviewed-on: https://pdfium-review.googlesource.com/29671 Commit-Queue: Tom Sepez <tsepez@chromium.org> Reviewed-by: Chris Palmer <palmer@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fpdfapi/page/cpdf_streamparser.cpp')
-rw-r--r--core/fpdfapi/page/cpdf_streamparser.cpp23
1 files changed, 11 insertions, 12 deletions
diff --git a/core/fpdfapi/page/cpdf_streamparser.cpp b/core/fpdfapi/page/cpdf_streamparser.cpp
index 3b6d12038f..c6660b799b 100644
--- a/core/fpdfapi/page/cpdf_streamparser.cpp
+++ b/core/fpdfapi/page/cpdf_streamparser.cpp
@@ -101,13 +101,12 @@ uint32_t DecodeInlineStream(const uint8_t* src_buf,
} // namespace
-CPDF_StreamParser::CPDF_StreamParser(const uint8_t* pData, uint32_t dwSize)
- : m_Size(dwSize), m_Pos(0), m_WordSize(0), m_pBuf(pData) {}
+CPDF_StreamParser::CPDF_StreamParser(pdfium::span<const uint8_t> span)
+ : m_pBuf(span) {}
-CPDF_StreamParser::CPDF_StreamParser(const uint8_t* pData,
- uint32_t dwSize,
+CPDF_StreamParser::CPDF_StreamParser(pdfium::span<const uint8_t> span,
const WeakPtr<ByteStringPool>& pPool)
- : m_Size(dwSize), m_Pos(0), m_WordSize(0), m_pBuf(pData), m_pPool(pPool) {}
+ : m_pPool(pPool), m_pBuf(span) {}
CPDF_StreamParser::~CPDF_StreamParser() {}
@@ -115,7 +114,7 @@ std::unique_ptr<CPDF_Stream> CPDF_StreamParser::ReadInlineStream(
CPDF_Document* pDoc,
std::unique_ptr<CPDF_Dictionary> pDict,
CPDF_Object* pCSObj) {
- if (m_Pos == m_Size)
+ if (m_Pos == m_pBuf.size())
return nullptr;
if (PDFCharIsWhitespace(m_pBuf[m_Pos]))
@@ -176,17 +175,17 @@ std::unique_ptr<CPDF_Stream> CPDF_StreamParser::ReadInlineStream(
std::unique_ptr<uint8_t, FxFreeDeleter> pData;
uint32_t dwStreamSize;
if (Decoder.IsEmpty()) {
- if (OrigSize > m_Size - m_Pos)
- OrigSize = m_Size - m_Pos;
+ if (OrigSize > m_pBuf.size() - m_Pos)
+ OrigSize = m_pBuf.size() - m_Pos;
pData.reset(FX_Alloc(uint8_t, OrigSize));
- memcpy(pData.get(), m_pBuf + m_Pos, OrigSize);
+ memcpy(pData.get(), &m_pBuf[m_Pos], OrigSize);
dwStreamSize = OrigSize;
m_Pos += OrigSize;
} else {
uint8_t* pIgnore = nullptr;
uint32_t dwDestSize = OrigSize;
dwStreamSize =
- DecodeInlineStream(m_pBuf + m_Pos, m_Size - m_Pos, width, height,
+ DecodeInlineStream(&m_pBuf[m_Pos], m_pBuf.size() - m_Pos, width, height,
Decoder, pParam, &pIgnore, &dwDestSize);
FX_Free(pIgnore);
if (static_cast<int>(dwStreamSize) < 0)
@@ -212,7 +211,7 @@ std::unique_ptr<CPDF_Stream> CPDF_StreamParser::ReadInlineStream(
}
m_Pos = dwSavePos;
pData.reset(FX_Alloc(uint8_t, dwStreamSize));
- memcpy(pData.get(), m_pBuf + m_Pos, dwStreamSize);
+ memcpy(pData.get(), &m_pBuf[m_Pos], dwStreamSize);
m_Pos += dwStreamSize;
}
pDict->SetNewFor<CPDF_Number>("Length", static_cast<int>(dwStreamSize));
@@ -603,5 +602,5 @@ ByteString CPDF_StreamParser::ReadHexString() {
}
bool CPDF_StreamParser::PositionIsInBounds() const {
- return m_Pos < m_Size;
+ return m_Pos < m_pBuf.size();
}