From 70ddc1ca22ad44a77006491b604a75f6514a4aa8 Mon Sep 17 00:00:00 2001 From: Artem Strygin Date: Wed, 25 Jul 2018 02:28:35 +0000 Subject: Use document size instead of file size while parsing. We should use document size instead of File size, because all offsets and sizes was read from document should take into account of header offset. Added some tests of parsing of documents with header offset. Also drop friendship of CPDF_SyntaxParser with CPDF_Parser. Change-Id: Iebec75ab2ee07fb644a6c653b4ef5c2e09af09fe Reviewed-on: https://pdfium-review.googlesource.com/35830 Commit-Queue: Art Snake Reviewed-by: Lei Zhang --- core/fpdfapi/parser/cpdf_parser.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'core/fpdfapi/parser/cpdf_parser.cpp') diff --git a/core/fpdfapi/parser/cpdf_parser.cpp b/core/fpdfapi/parser/cpdf_parser.cpp index 16077fd39e..be18560ffc 100644 --- a/core/fpdfapi/parser/cpdf_parser.cpp +++ b/core/fpdfapi/parser/cpdf_parser.cpp @@ -119,10 +119,6 @@ bool CPDF_Parser::IsObjectFree(uint32_t objnum) const { return GetObjectType(objnum) == ObjectType::kFree; } -RetainPtr CPDF_Parser::GetFileAccess() const { - return m_pSyntax->GetFileAccess(); -} - void CPDF_Parser::ShrinkObjectMap(uint32_t objnum) { m_CrossRefTable->ShrinkObjectMap(objnum); } @@ -230,8 +226,7 @@ CPDF_Parser::Error CPDF_Parser::StartParseInternal() { FX_FILESIZE CPDF_Parser::ParseStartXRef() { static constexpr char kStartXRefKeyword[] = "startxref"; - m_pSyntax->SetPos(m_pSyntax->m_FileLen - m_pSyntax->m_HeaderOffset - - strlen(kStartXRefKeyword)); + m_pSyntax->SetPos(m_pSyntax->GetDocumentSize() - strlen(kStartXRefKeyword)); if (!m_pSyntax->BackwardsSearchToWord(kStartXRefKeyword, 4096)) return 0; @@ -245,7 +240,7 @@ FX_FILESIZE CPDF_Parser::ParseStartXRef() { return 0; const FX_SAFE_FILESIZE result = FXSYS_atoi64(xrefpos_str.c_str()); - if (!result.IsValid() || result.ValueOrDie() >= GetFileAccess()->GetSize()) + if (!result.IsValid() || result.ValueOrDie() >= m_pSyntax->GetDocumentSize()) return 0; return result.ValueOrDie(); @@ -453,7 +448,7 @@ bool CPDF_Parser::ParseAndAppendCrossRefSubsectionData( return false; const size_t max_entries_in_file = - m_pSyntax->GetFileAccess()->GetSize() / kEntryConstSize; + m_pSyntax->GetDocumentSize() / kEntryConstSize; if (new_size.ValueOrDie() > max_entries_in_file) return false; -- cgit v1.2.3