diff options
author | Artem Strygin <art-snake@yandex-team.ru> | 2017-08-29 00:22:48 +0300 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-08-28 21:49:03 +0000 |
commit | 6e63fd32cd816210189516e92f0a650788f5f4f8 (patch) | |
tree | ca4f905470e4d563676ac3015178830c0f3d77e0 /core/fpdfapi | |
parent | 38adfc184a53fbe472e48867acfc201ed940e8ee (diff) | |
download | pdfium-6e63fd32cd816210189516e92f0a650788f5f4f8.tar.xz |
Unify CPDF_DataAvail::CheckTrailer.
Use read validator to check trailer availability
Change-Id: Id8c62a6c746f136c05cfa8d646268322e2543b52
Reviewed-on: https://pdfium-review.googlesource.com/11770
Commit-Queue: Art Snake <art-snake@yandex-team.ru>
Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fpdfapi')
-rw-r--r-- | core/fpdfapi/parser/cpdf_data_avail.cpp | 57 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_data_avail.h | 4 |
2 files changed, 12 insertions, 49 deletions
diff --git a/core/fpdfapi/parser/cpdf_data_avail.cpp b/core/fpdfapi/parser/cpdf_data_avail.cpp index 9d6b2f4bef..43897a464c 100644 --- a/core/fpdfapi/parser/cpdf_data_avail.cpp +++ b/core/fpdfapi/parser/cpdf_data_avail.cpp @@ -275,9 +275,7 @@ bool CPDF_DataAvail::CheckDocStatus(DownloadHints* pHints) { case PDF_DATAAVAIL_CROSSREF_ITEM: return CheckCrossRefItem(); case PDF_DATAAVAIL_TRAILER: - return CheckTrailer(pHints); - case PDF_DATAAVAIL_TRAILER_APPEND: - return CheckTrailerAppend(pHints); + return CheckTrailer(); case PDF_DATAAVAIL_LOADALLCROSSREF: return LoadAllXref(pHints); case PDF_DATAAVAIL_LOADALLFILE: @@ -921,49 +919,16 @@ bool CPDF_DataAvail::CheckCrossRef() { return true; } -bool CPDF_DataAvail::CheckTrailerAppend(DownloadHints* pHints) { - if (m_Pos < m_dwFileLen) { - FX_FILESIZE dwAppendPos = m_Pos + m_syntaxParser.GetPos(); - int32_t iSize = (int32_t)( - dwAppendPos + 512 > m_dwFileLen ? m_dwFileLen - dwAppendPos : 512); +bool CPDF_DataAvail::CheckTrailer() { + m_syntaxParser.InitParser(m_pFileRead, 0); - if (!m_pFileAvail->IsDataAvail(dwAppendPos, iSize)) { - pHints->AddSegment(dwAppendPos, iSize); - return false; - } - } - - if (m_dwPrevXRefOffset) { - SetStartOffset(m_dwPrevXRefOffset); - m_docStatus = PDF_DATAAVAIL_CROSSREF; - } else { - m_docStatus = PDF_DATAAVAIL_LOADALLCROSSREF; - } - return true; -} - -bool CPDF_DataAvail::CheckTrailer(DownloadHints* pHints) { - int32_t iTrailerSize = - (int32_t)(m_Pos + 512 > m_dwFileLen ? m_dwFileLen - m_Pos : 512); - if (!m_pFileAvail->IsDataAvail(m_Pos, iTrailerSize)) { - pHints->AddSegment(m_Pos, iTrailerSize); - return false; - } - - int32_t iSize = (int32_t)(m_Pos + iTrailerSize - m_dwTrailerOffset); - std::vector<uint8_t> buf(iSize); - if (!m_pFileRead->ReadBlock(buf.data(), m_dwTrailerOffset, iSize)) - return false; - - auto file = pdfium::MakeRetain<CFX_MemoryStream>( - buf.data(), static_cast<size_t>(iSize), false); - m_syntaxParser.InitParser(file, 0); - - std::unique_ptr<CPDF_Object> pTrailer( - m_syntaxParser.GetObject(nullptr, 0, 0, true)); + const CPDF_ReadValidator::Session read_session(GetValidator().Get()); + m_syntaxParser.SetPos(m_dwTrailerOffset); + const std::unique_ptr<CPDF_Object> pTrailer = + m_syntaxParser.GetObject(nullptr, 0, 0, true); if (!pTrailer) { - m_Pos += m_syntaxParser.GetPos(); - pHints->AddSegment(m_Pos, iTrailerSize); + if (!GetValidator()->has_read_problems()) + m_docStatus = PDF_DATAAVAIL_ERROR; return false; } @@ -980,7 +945,7 @@ bool CPDF_DataAvail::CheckTrailer(DownloadHints* pHints) { uint32_t xrefpos = GetDirectInteger(pTrailerDict, "Prev"); if (!xrefpos) { m_dwPrevXRefOffset = 0; - m_docStatus = PDF_DATAAVAIL_TRAILER_APPEND; + m_docStatus = PDF_DATAAVAIL_LOADALLCROSSREF; return true; } @@ -995,7 +960,7 @@ bool CPDF_DataAvail::CheckTrailer(DownloadHints* pHints) { m_docStatus = PDF_DATAAVAIL_LOADALLFILE; } else { SetStartOffset(m_dwPrevXRefOffset); - m_docStatus = PDF_DATAAVAIL_TRAILER_APPEND; + m_docStatus = PDF_DATAAVAIL_CROSSREF; } return true; } diff --git a/core/fpdfapi/parser/cpdf_data_avail.h b/core/fpdfapi/parser/cpdf_data_avail.h index 57fcc96eb7..1f2a1f2475 100644 --- a/core/fpdfapi/parser/cpdf_data_avail.h +++ b/core/fpdfapi/parser/cpdf_data_avail.h @@ -43,7 +43,6 @@ enum PDF_DATAAVAIL_STATUS { PDF_DATAAVAIL_DONE, PDF_DATAAVAIL_ERROR, PDF_DATAAVAIL_LOADALLFILE, - PDF_DATAAVAIL_TRAILER_APPEND }; enum PDF_PAGENODE_TYPE { @@ -135,7 +134,7 @@ class CPDF_DataAvail final { bool CheckEnd(); bool CheckCrossRef(); bool CheckCrossRefItem(); - bool CheckTrailer(DownloadHints* pHints); + bool CheckTrailer(); bool CheckRoot(); bool CheckInfo(); bool CheckPages(); @@ -143,7 +142,6 @@ class CPDF_DataAvail final { bool CheckResources(); bool CheckAcroForm(); bool CheckAcroFormSubObject(); - bool CheckTrailerAppend(DownloadHints* pHints); bool CheckPageStatus(); bool IsLinearizedFile(uint8_t* pData, uint32_t dwLen); |