Change CPDF_SyntaxParser::ReadBlock() to take a span.
Change-Id: Id0cbfb6e12549e769f5ff97462d5e9d32c4a4cf5
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/100573
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/parser/cpdf_parser.cpp b/core/fpdfapi/parser/cpdf_parser.cpp
index aa85f81..4b3b407 100644
--- a/core/fpdfapi/parser/cpdf_parser.cpp
+++ b/core/fpdfapi/parser/cpdf_parser.cpp
@@ -517,10 +517,9 @@
while (entries_to_read > 0) {
const uint32_t entries_in_block = std::min(entries_to_read, 1024u);
const uint32_t bytes_to_read = entries_in_block * kEntrySize;
- if (!m_pSyntax->ReadBlock(reinterpret_cast<uint8_t*>(buf.data()),
- bytes_to_read)) {
+ auto block_span = pdfium::make_span(buf).first(bytes_to_read);
+ if (!m_pSyntax->ReadBlock(pdfium::as_writable_bytes(block_span)))
return false;
- }
for (uint32_t i = 0; i < entries_in_block; i++) {
uint32_t iObjectIndex = count - entries_to_read + i;
@@ -1201,7 +1200,8 @@
while (src_size) {
const uint32_t block_size =
static_cast<uint32_t>(std::min(kBufferSize, src_size));
- if (!m_pSyntax->ReadBlock(buffer.data(), block_size))
+ auto block_span = pdfium::make_span(buffer).first(block_size);
+ if (!m_pSyntax->ReadBlock(block_span))
return false;
if (!archive->WriteBlock(pdfium::make_span(buffer).first(block_size)))
return false;
diff --git a/core/fpdfapi/parser/cpdf_syntax_parser.cpp b/core/fpdfapi/parser/cpdf_syntax_parser.cpp
index ffbc42f..0a85e8e 100644
--- a/core/fpdfapi/parser/cpdf_syntax_parser.cpp
+++ b/core/fpdfapi/parser/cpdf_syntax_parser.cpp
@@ -163,10 +163,10 @@
return true;
}
-bool CPDF_SyntaxParser::ReadBlock(uint8_t* pBuf, uint32_t size) {
- if (!m_pFileAccess->ReadBlockAtOffset({pBuf, size}, m_Pos + m_HeaderOffset))
+bool CPDF_SyntaxParser::ReadBlock(pdfium::span<uint8_t> buffer) {
+ if (!m_pFileAccess->ReadBlockAtOffset(buffer, m_Pos + m_HeaderOffset))
return false;
- m_Pos += size;
+ m_Pos += buffer.size();
return true;
}
diff --git a/core/fpdfapi/parser/cpdf_syntax_parser.h b/core/fpdfapi/parser/cpdf_syntax_parser.h
index 7985a72..dfd5f5a 100644
--- a/core/fpdfapi/parser/cpdf_syntax_parser.h
+++ b/core/fpdfapi/parser/cpdf_syntax_parser.h
@@ -19,6 +19,7 @@
#include "core/fxcrt/string_pool_template.h"
#include "core/fxcrt/unowned_ptr.h"
#include "core/fxcrt/weak_ptr.h"
+#include "third_party/base/span.h"
class CPDF_Dictionary;
class CPDF_IndirectObjectHolder;
@@ -62,7 +63,7 @@
void RecordingToNextWord();
bool BackwardsSearchToWord(ByteStringView word, FX_FILESIZE limit);
FX_FILESIZE FindTag(ByteStringView tag);
- bool ReadBlock(uint8_t* pBuf, uint32_t size);
+ bool ReadBlock(pdfium::span<uint8_t> buffer);
bool GetCharAt(FX_FILESIZE pos, uint8_t& ch);
WordResult GetNextWord();
ByteString PeekNextWord();