summaryrefslogtreecommitdiff
path: root/core/fpdfapi
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-07-25 20:57:25 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-07-25 20:57:25 +0000
commita35063cb627d611e77816216d0d8946794a98079 (patch)
tree458125d329ef663797001d78a9181429085ec9b5 /core/fpdfapi
parent35b51e95b9a4d0c064efd905e946a554d6f47890 (diff)
downloadpdfium-a35063cb627d611e77816216d0d8946794a98079.tar.xz
Change GetHeaderOffset() to return Optional<FX_FILESIZE>.
Remove |kInvalidHeaderOffset|. Change-Id: I5978e745e97aa4e13299dd21028721725ac0c996 Reviewed-on: https://pdfium-review.googlesource.com/38853 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Art Snake <art-snake@yandex-team.ru>
Diffstat (limited to 'core/fpdfapi')
-rw-r--r--core/fpdfapi/parser/cpdf_data_avail.cpp6
-rw-r--r--core/fpdfapi/parser/cpdf_parser.cpp8
-rw-r--r--core/fpdfapi/parser/fpdf_parser_utility.cpp13
-rw-r--r--core/fpdfapi/parser/fpdf_parser_utility.h12
4 files changed, 20 insertions, 19 deletions
diff --git a/core/fpdfapi/parser/cpdf_data_avail.cpp b/core/fpdfapi/parser/cpdf_data_avail.cpp
index 577b7e7a18..41d410a87b 100644
--- a/core/fpdfapi/parser/cpdf_data_avail.cpp
+++ b/core/fpdfapi/parser/cpdf_data_avail.cpp
@@ -499,15 +499,15 @@ CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::CheckHeaderAndLinearized() {
return DocAvailStatus::DataAvailable;
const CPDF_ReadValidator::Session read_session(GetValidator().Get());
- const int32_t header_offset = GetHeaderOffset(GetValidator());
+ const Optional<FX_FILESIZE> header_offset = GetHeaderOffset(GetValidator());
if (GetValidator()->has_read_problems())
return DocAvailStatus::DataNotAvailable;
- if (header_offset == kInvalidHeaderOffset)
+ if (!header_offset)
return DocAvailStatus::DataError;
m_parser.m_pSyntax =
- pdfium::MakeUnique<CPDF_SyntaxParser>(GetValidator(), header_offset);
+ pdfium::MakeUnique<CPDF_SyntaxParser>(GetValidator(), *header_offset);
m_pLinearized = m_parser.ParseLinearizedHeader();
if (GetValidator()->has_read_problems())
return DocAvailStatus::DataNotAvailable;
diff --git a/core/fpdfapi/parser/cpdf_parser.cpp b/core/fpdfapi/parser/cpdf_parser.cpp
index ba8974a0de..e93f293f84 100644
--- a/core/fpdfapi/parser/cpdf_parser.cpp
+++ b/core/fpdfapi/parser/cpdf_parser.cpp
@@ -121,13 +121,13 @@ void CPDF_Parser::ShrinkObjectMap(uint32_t objnum) {
bool CPDF_Parser::InitSyntaxParser(
const RetainPtr<CPDF_ReadValidator>& validator) {
- const int32_t header_offset = GetHeaderOffset(validator);
- if (header_offset == kInvalidHeaderOffset)
+ const Optional<FX_FILESIZE> header_offset = GetHeaderOffset(validator);
+ if (!header_offset)
return false;
- if (validator->GetSize() < header_offset + kPDFHeaderSize)
+ if (validator->GetSize() < *header_offset + kPDFHeaderSize)
return false;
- m_pSyntax = pdfium::MakeUnique<CPDF_SyntaxParser>(validator, header_offset);
+ m_pSyntax = pdfium::MakeUnique<CPDF_SyntaxParser>(validator, *header_offset);
return ParseFileVersion();
}
diff --git a/core/fpdfapi/parser/fpdf_parser_utility.cpp b/core/fpdfapi/parser/fpdf_parser_utility.cpp
index 3c99415d21..83c967d8c2 100644
--- a/core/fpdfapi/parser/fpdf_parser_utility.cpp
+++ b/core/fpdfapi/parser/fpdf_parser_utility.cpp
@@ -71,17 +71,18 @@ const char PDF_CharType[256] = {
'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R',
'R', 'R', 'R', 'R', 'R', 'R', 'R', 'W'};
-int32_t GetHeaderOffset(const RetainPtr<IFX_SeekableReadStream>& pFile) {
- const size_t kBufSize = 4;
+Optional<FX_FILESIZE> GetHeaderOffset(
+ const RetainPtr<IFX_SeekableReadStream>& pFile) {
+ static constexpr size_t kBufSize = 4;
uint8_t buf[kBufSize];
- for (int32_t offset = 0; offset <= 1024; ++offset) {
+ for (FX_FILESIZE offset = 0; offset <= 1024; ++offset) {
if (!pFile->ReadBlock(buf, offset, kBufSize))
- return kInvalidHeaderOffset;
+ return {};
if (memcmp(buf, "%PDF", 4) == 0)
return offset;
}
- return kInvalidHeaderOffset;
+ return {};
}
int32_t GetDirectInteger(const CPDF_Dictionary* pDict, const ByteString& key) {
@@ -114,7 +115,7 @@ ByteString PDF_NameDecode(const ByteStringView& bstr) {
}
ByteString PDF_NameEncode(const ByteString& orig) {
- uint8_t* src_buf = (uint8_t*)orig.c_str();
+ const uint8_t* src_buf = reinterpret_cast<const uint8_t*>(orig.c_str());
int src_len = orig.GetLength();
int dest_len = 0;
int i;
diff --git a/core/fpdfapi/parser/fpdf_parser_utility.h b/core/fpdfapi/parser/fpdf_parser_utility.h
index 7529fbc484..5fe9b5d4a9 100644
--- a/core/fpdfapi/parser/fpdf_parser_utility.h
+++ b/core/fpdfapi/parser/fpdf_parser_utility.h
@@ -11,10 +11,11 @@
#include "core/fxcrt/fx_string.h"
#include "core/fxcrt/retain_ptr.h"
+#include "third_party/base/optional.h"
-class IFX_SeekableReadStream;
class CPDF_Dictionary;
class CPDF_Object;
+class IFX_SeekableReadStream;
// Use the accessors below instead of directly accessing PDF_CharType.
extern const char PDF_CharType[256];
@@ -36,12 +37,11 @@ inline bool PDFCharIsLineEnding(uint8_t c) {
return c == '\r' || c == '\n';
}
-constexpr int32_t kInvalidHeaderOffset = -1;
-
-// On success, return a positive offset value to the PDF header.. If the header
+// On success, return a positive offset value to the PDF header. If the header
// cannot be found, or if there is an error reading from |pFile|, then return
-// |kInvalidHeaderOffset|.
-int32_t GetHeaderOffset(const RetainPtr<IFX_SeekableReadStream>& pFile);
+// nullopt.
+Optional<FX_FILESIZE> GetHeaderOffset(
+ const RetainPtr<IFX_SeekableReadStream>& pFile);
int32_t GetDirectInteger(const CPDF_Dictionary* pDict, const ByteString& key);