From e16ffd4fc3f286ebfaf7820351d4fee680deca88 Mon Sep 17 00:00:00 2001 From: Artem Strygin Date: Thu, 14 Jun 2018 14:30:07 +0000 Subject: Simplify the calculation of Pages Offsets within CPDF_HintsTable. Change-Id: I020fd5ae11b32f753d681e7e0c26b7f95e920bff Reviewed-on: https://pdfium-review.googlesource.com/15812 Reviewed-by: dsinclair Commit-Queue: Art Snake --- core/fpdfapi/parser/cpdf_hint_tables.cpp | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/core/fpdfapi/parser/cpdf_hint_tables.cpp b/core/fpdfapi/parser/cpdf_hint_tables.cpp index a412fdc34d..7d371909e9 100644 --- a/core/fpdfapi/parser/cpdf_hint_tables.cpp +++ b/core/fpdfapi/parser/cpdf_hint_tables.cpp @@ -156,28 +156,21 @@ bool CPDF_HintTables::ReadPageHintTable(CFX_BitStream* hStream) { dwPageLenArray.push_back(safePageLen.ValueOrDie()); } - const FX_FILESIZE nOffsetE = m_pLinearized->GetFirstPageEndOffset(); const uint32_t nFirstPageNum = m_pLinearized->GetFirstPageNo(); + if (nFirstPageNum >= nPages) + return false; + + m_szPageOffsetArray.resize(nPages, 0); + ASSERT(m_szFirstPageObjOffset); + m_szPageOffsetArray[nFirstPageNum] = m_szFirstPageObjOffset; + FX_FILESIZE prev_page_offset = m_pLinearized->GetFirstPageEndOffset(); for (uint32_t i = 0; i < nPages; ++i) { - if (i == nFirstPageNum) { - m_szPageOffsetArray.push_back(m_szFirstPageObjOffset); - } else if (i == nFirstPageNum + 1) { - if (i == 1) { - m_szPageOffsetArray.push_back(nOffsetE); - } else { - m_szPageOffsetArray.push_back(m_szPageOffsetArray[i - 2] + - dwPageLenArray[i - 2]); - } - } else { - if (i == 0) { - m_szPageOffsetArray.push_back(nOffsetE); - } else { - m_szPageOffsetArray.push_back(m_szPageOffsetArray[i - 1] + - dwPageLenArray[i - 1]); - } - } - } + if (i == nFirstPageNum) + continue; + m_szPageOffsetArray[i] = prev_page_offset; + prev_page_offset += dwPageLenArray[i]; + } m_szPageOffsetArray.push_back(m_szPageOffsetArray[nPages - 1] + dwPageLenArray[nPages - 1]); hStream->ByteAlign(); -- cgit v1.2.3