diff options
author | Artem Strygin <art-snake@yandex-team.ru> | 2017-08-23 17:40:40 +0300 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-08-28 21:02:22 +0000 |
commit | 4a1493d73135d87d1d4417dd168c92e8902dd12d (patch) | |
tree | 074ed195be883756d84e82efa80460a170eefef0 | |
parent | 93ed5f640ce24dae3f0bbf8eeb38e3cc83909a60 (diff) | |
download | pdfium-4a1493d73135d87d1d4417dd168c92e8902dd12d.tar.xz |
Unify CPDF_DataAvail::LoadAllFile.chromium/3199
Use read validator to check whole file availability.
Change-Id: Ic118ccee38557d124ecde3893ee3c18c98c674d5
Reviewed-on: https://pdfium-review.googlesource.com/11712
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
-rw-r--r-- | core/fpdfapi/parser/cpdf_data_avail.cpp | 32 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_data_avail.h | 8 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_read_validator.cpp | 24 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_read_validator.h | 6 |
4 files changed, 49 insertions, 21 deletions
diff --git a/core/fpdfapi/parser/cpdf_data_avail.cpp b/core/fpdfapi/parser/cpdf_data_avail.cpp index 234a5a0b19..9d6b2f4bef 100644 --- a/core/fpdfapi/parser/cpdf_data_avail.cpp +++ b/core/fpdfapi/parser/cpdf_data_avail.cpp @@ -281,7 +281,7 @@ bool CPDF_DataAvail::CheckDocStatus(DownloadHints* pHints) { case PDF_DATAAVAIL_LOADALLCROSSREF: return LoadAllXref(pHints); case PDF_DATAAVAIL_LOADALLFILE: - return LoadAllFile(pHints); + return LoadAllFile(); case PDF_DATAAVAIL_ROOT: return CheckRoot(); case PDF_DATAAVAIL_INFO: @@ -298,7 +298,7 @@ bool CPDF_DataAvail::CheckDocStatus(DownloadHints* pHints) { m_docStatus = PDF_DATAAVAIL_PAGE_LATERLOAD; return true; case PDF_DATAAVAIL_ERROR: - return LoadAllFile(pHints); + return LoadAllFile(); case PDF_DATAAVAIL_PAGE_LATERLOAD: m_docStatus = PDF_DATAAVAIL_PAGE; default: @@ -307,14 +307,14 @@ bool CPDF_DataAvail::CheckDocStatus(DownloadHints* pHints) { } } -bool CPDF_DataAvail::CheckPageStatus(DownloadHints* pHints) { +bool CPDF_DataAvail::CheckPageStatus() { switch (m_docStatus) { case PDF_DATAAVAIL_PAGETREE: return CheckPages(); case PDF_DATAAVAIL_PAGE: return CheckPage(); case PDF_DATAAVAIL_ERROR: - return LoadAllFile(pHints); + return LoadAllFile(); default: m_bPagesTreeLoad = true; m_bPagesLoad = true; @@ -322,13 +322,12 @@ bool CPDF_DataAvail::CheckPageStatus(DownloadHints* pHints) { } } -bool CPDF_DataAvail::LoadAllFile(DownloadHints* pHints) { - if (m_pFileAvail->IsDataAvail(0, (uint32_t)m_dwFileLen)) { +bool CPDF_DataAvail::LoadAllFile() { + if (GetValidator()->IsWholeFileAvailable()) { m_docStatus = PDF_DATAAVAIL_DONE; return true; } - - pHints->AddSegment(0, (uint32_t)m_dwFileLen); + GetValidator()->ScheduleDownloadWholeFile(); return false; } @@ -1001,7 +1000,7 @@ bool CPDF_DataAvail::CheckTrailer(DownloadHints* pHints) { return true; } -bool CPDF_DataAvail::CheckPage(uint32_t dwPage, DownloadHints* pHints) { +bool CPDF_DataAvail::CheckPage(uint32_t dwPage) { while (true) { switch (m_docStatus) { case PDF_DATAAVAIL_PAGETREE: @@ -1013,7 +1012,7 @@ bool CPDF_DataAvail::CheckPage(uint32_t dwPage, DownloadHints* pHints) { return false; break; case PDF_DATAAVAIL_ERROR: - return LoadAllFile(pHints); + return LoadAllFile(); default: m_bPagesTreeLoad = true; m_bPagesLoad = true; @@ -1225,9 +1224,9 @@ bool CPDF_DataAvail::LoadDocPages() { return false; } -bool CPDF_DataAvail::LoadPages(DownloadHints* pHints) { +bool CPDF_DataAvail::LoadPages() { while (!m_bPagesTreeLoad) { - if (!CheckPageStatus(pHints)) + if (!CheckPageStatus()) return false; } @@ -1359,22 +1358,21 @@ CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsPageAvail( } if (!m_bMainXRefLoadedOK) { - if (!LoadAllFile(pHints)) + if (!LoadAllFile()) return DataNotAvailable; m_pDocument->GetParser()->RebuildCrossRef(); ResetFirstCheck(dwPage); return DataAvailable; } if (m_bTotalLoadPageTree) { - if (!LoadPages(pHints)) + if (!LoadPages()) return DataNotAvailable; } else { - if (!m_bCurPageDictLoadOK && !CheckPage(dwPage, pHints)) + if (!m_bCurPageDictLoadOK && !CheckPage(dwPage)) return DataNotAvailable; } } else { - if (!m_bTotalLoadPageTree && !m_bCurPageDictLoadOK && - !CheckPage(dwPage, pHints)) { + if (!m_bTotalLoadPageTree && !m_bCurPageDictLoadOK && !CheckPage(dwPage)) { return DataNotAvailable; } } diff --git a/core/fpdfapi/parser/cpdf_data_avail.h b/core/fpdfapi/parser/cpdf_data_avail.h index e704e12900..57fcc96eb7 100644 --- a/core/fpdfapi/parser/cpdf_data_avail.h +++ b/core/fpdfapi/parser/cpdf_data_avail.h @@ -144,7 +144,7 @@ class CPDF_DataAvail final { bool CheckAcroForm(); bool CheckAcroFormSubObject(); bool CheckTrailerAppend(DownloadHints* pHints); - bool CheckPageStatus(DownloadHints* pHints); + bool CheckPageStatus(); bool IsLinearizedFile(uint8_t* pData, uint32_t dwLen); void SetStartOffset(FX_FILESIZE dwOffset); @@ -158,14 +158,14 @@ class CPDF_DataAvail final { bool* pExistInFile); bool GetPageKids(CPDF_Parser* pParser, CPDF_Object* pPages); bool PreparePageItem(); - bool LoadPages(DownloadHints* pHints); + bool LoadPages(); bool LoadAllXref(DownloadHints* pHints); - bool LoadAllFile(DownloadHints* pHints); + bool LoadAllFile(); DocAvailStatus CheckLinearizedData(DownloadHints* pHints); bool CheckPageAnnots(uint32_t dwPage); DocAvailStatus CheckLinearizedFirstPage(uint32_t dwPage); - bool CheckPage(uint32_t dwPage, DownloadHints* pHints); + bool CheckPage(uint32_t dwPage); bool LoadDocPages(); bool LoadDocPage(uint32_t dwPage); bool CheckPageNode(const PageNode& pageNode, diff --git a/core/fpdfapi/parser/cpdf_read_validator.cpp b/core/fpdfapi/parser/cpdf_read_validator.cpp index be20f18f33..d01b3c61e6 100644 --- a/core/fpdfapi/parser/cpdf_read_validator.cpp +++ b/core/fpdfapi/parser/cpdf_read_validator.cpp @@ -84,6 +84,13 @@ FX_FILESIZE CPDF_ReadValidator::GetSize() { } void CPDF_ReadValidator::ScheduleDownload(FX_FILESIZE offset, size_t size) { + const FX_SAFE_UINT32 safe_size = size; + if (safe_size.IsValid()) + ScheduleDataDownload(offset, safe_size.ValueOrDie()); +} + +void CPDF_ReadValidator::ScheduleDataDownload(FX_FILESIZE offset, + uint32_t size) { if (!hints_ || size == 0) return; @@ -105,3 +112,20 @@ void CPDF_ReadValidator::ScheduleDownload(FX_FILESIZE offset, size_t size) { } hints_->AddSegment(start_segment_offset, segment_size.ValueOrDie()); } + +void CPDF_ReadValidator::ScheduleDownloadWholeFile() { + const FX_SAFE_UINT32 safe_size = GetSize(); + if (safe_size.IsValid()) + ScheduleDataDownload(0, safe_size.ValueOrDie()); +} + +bool CPDF_ReadValidator::IsDataRangeAvailable(FX_FILESIZE offset, + uint32_t size) const { + return !file_avail_ || file_avail_->IsDataAvail(offset, size); +} + +bool CPDF_ReadValidator::IsWholeFileAvailable() { + const FX_SAFE_UINT32 safe_size = GetSize(); + return safe_size.IsValid() ? IsDataRangeAvailable(0, safe_size.ValueOrDie()) + : false; +} diff --git a/core/fpdfapi/parser/cpdf_read_validator.h b/core/fpdfapi/parser/cpdf_read_validator.h index 9cc22c1ccc..106f6e437b 100644 --- a/core/fpdfapi/parser/cpdf_read_validator.h +++ b/core/fpdfapi/parser/cpdf_read_validator.h @@ -36,6 +36,12 @@ class CPDF_ReadValidator : public IFX_SeekableReadStream { void ResetErrors(); + bool IsDataRangeAvailable(FX_FILESIZE offset, uint32_t size) const; + bool IsWholeFileAvailable(); + + void ScheduleDataDownload(FX_FILESIZE offset, uint32_t size); + void ScheduleDownloadWholeFile(); + // IFX_SeekableReadStream overrides: bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override; FX_FILESIZE GetSize() override; |