diff options
author | art-snake <art-snake@yandex-team.ru> | 2016-10-31 12:25:30 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-10-31 12:25:30 -0700 |
commit | 461b1d93f717e248ceb3c1e1bbb8285ba3258f8c (patch) | |
tree | 6af82267214e3ff24cbf9a8f376a8ab59c5f7cc9 /core/fpdfapi/parser/cpdf_data_avail.cpp | |
parent | 96c7b33510c5d48ef5707326de88b35dcd2e4b45 (diff) | |
download | pdfium-461b1d93f717e248ceb3c1e1bbb8285ba3258f8c.tar.xz |
Fix loading page using hint tables.
When linearized document have hint table,
The FPDFAvail_IsPageAvail return true,
but FPDF_LoadPage return nullptr, for non first pages.
This happens, bacause document not use hint tables, to load page.
To fix this, I force save the page's ObjNum in document.
This is restoring of original fix:
https://codereview.chromium.org/2437773003/
Review-Url: https://codereview.chromium.org/2444903002
Diffstat (limited to 'core/fpdfapi/parser/cpdf_data_avail.cpp')
-rw-r--r-- | core/fpdfapi/parser/cpdf_data_avail.cpp | 52 |
1 files changed, 27 insertions, 25 deletions
diff --git a/core/fpdfapi/parser/cpdf_data_avail.cpp b/core/fpdfapi/parser/cpdf_data_avail.cpp index c6a434be5d..318f2cf54d 100644 --- a/core/fpdfapi/parser/cpdf_data_avail.cpp +++ b/core/fpdfapi/parser/cpdf_data_avail.cpp @@ -1626,7 +1626,7 @@ CPDF_DataAvail::DocAvailStatus CPDF_DataAvail::IsPageAvail( if (nResult != DataAvailable) return nResult; m_pagesLoadState.insert(dwPage); - return DataAvailable; + return GetPage(dwPage) ? DataAvailable : DataError; } if (m_bMainXRefLoadedOK) { @@ -1751,31 +1751,33 @@ int CPDF_DataAvail::GetPageCount() const { CPDF_Dictionary* CPDF_DataAvail::GetPage(int index) { if (!m_pDocument || index < 0 || index >= GetPageCount()) return nullptr; + CPDF_Dictionary* page = m_pDocument->GetPage(index); + if (page) + return page; + if (!m_pLinearized || !m_pHintTables) + return nullptr; - if (m_pLinearized) { - CPDF_Dictionary* pDict = m_pLinearized->GetDict(); - CPDF_Object* pObj = pDict ? pDict->GetDirectObjectFor("P") : nullptr; - - int pageNum = pObj ? pObj->GetInteger() : 0; - if (m_pHintTables && index != pageNum) { - FX_FILESIZE szPageStartPos = 0; - FX_FILESIZE szPageLength = 0; - uint32_t dwObjNum = 0; - bool bPagePosGot = m_pHintTables->GetPagePos(index, &szPageStartPos, - &szPageLength, &dwObjNum); - if (!bPagePosGot) - return nullptr; - - m_syntaxParser.InitParser(m_pFileRead, (uint32_t)szPageStartPos); - CPDF_Object* pPageDict = ParseIndirectObjectAt(0, dwObjNum, m_pDocument); - if (!pPageDict) - return nullptr; - - if (!m_pDocument->ReplaceIndirectObjectIfHigherGeneration(dwObjNum, - pPageDict)) { - return nullptr; - } - return pPageDict->GetDict(); + CPDF_Dictionary* pDict = m_pLinearized->GetDict(); + CPDF_Object* pObj = pDict ? pDict->GetDirectObjectFor("P") : nullptr; + int firstPageNum = pObj ? pObj->GetInteger() : 0; + if (index == firstPageNum) + return nullptr; + FX_FILESIZE szPageStartPos = 0; + FX_FILESIZE szPageLength = 0; + uint32_t dwObjNum = 0; + const bool bPagePosGot = m_pHintTables->GetPagePos(index, &szPageStartPos, + &szPageLength, &dwObjNum); + if (!bPagePosGot || !dwObjNum) + return nullptr; + // We should say to the document, which object is the page. + m_pDocument->SetPageObjNum(index, dwObjNum); + // Page object already can be parsed in document. + CPDF_Object* pPageDict = m_pDocument->GetIndirectObject(dwObjNum); + if (!pPageDict) { + m_syntaxParser.InitParser(m_pFileRead, (uint32_t)szPageStartPos); + pPageDict = ParseIndirectObjectAt(0, dwObjNum, m_pDocument); + if (pPageDict) { + m_pDocument->ReplaceIndirectObjectIfHigherGeneration(dwObjNum, pPageDict); } } return m_pDocument->GetPage(index); |