summaryrefslogtreecommitdiff
path: root/core/fpdfapi
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfapi')
-rw-r--r--core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp19
-rw-r--r--core/fpdfapi/fpdf_parser/cpdf_hint_tables.h15
2 files changed, 24 insertions, 10 deletions
diff --git a/core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp b/core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp
index 4d48ab4bfa..f1e74dc6bc 100644
--- a/core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp
+++ b/core/fpdfapi/fpdf_parser/cpdf_hint_tables.cpp
@@ -60,6 +60,8 @@ bool CPDF_HintTables::ReadPageHintTable(CFX_BitStream* hStream) {
// Item 1: The least number of objects in a page.
uint32_t dwObjLeastNum = hStream->GetBits(32);
+ if (!dwObjLeastNum)
+ return FALSE;
// Item 2: The location of the first page's page object.
uint32_t dwFirstObjLoc = hStream->GetBits(32);
@@ -78,13 +80,19 @@ bool CPDF_HintTables::ReadPageHintTable(CFX_BitStream* hStream) {
// Item 3: The number of bits needed to represent the difference
// between the greatest and least number of objects in a page.
uint32_t dwDeltaObjectsBits = hStream->GetBits(16);
+ if (!dwDeltaObjectsBits)
+ return FALSE;
// Item 4: The least length of a page in bytes.
uint32_t dwPageLeastLen = hStream->GetBits(32);
+ if (!dwPageLeastLen)
+ return FALSE;
// Item 5: The number of bits needed to represent the difference
// between the greatest and least length of a page, in bytes.
uint32_t dwDeltaPageLenBits = hStream->GetBits(16);
+ if (!dwDeltaPageLenBits)
+ return FALSE;
// Skip Item 6, 7, 8, 9 total 96 bits.
hStream->SkipBits(96);
@@ -96,12 +104,16 @@ bool CPDF_HintTables::ReadPageHintTable(CFX_BitStream* hStream) {
// Item 11: The number of bits needed to represent the numerically
// greatest shared object identifier used by the pages.
uint32_t dwSharedIdBits = hStream->GetBits(16);
+ if (!dwSharedObjBits)
+ return FALSE;
// Item 12: The number of bits needed to represent the numerator of
// the fractional position for each shared object reference. For each
// shared object referenced from a page, there is an indication of
// where in the page's content stream the object is first referenced.
uint32_t dwSharedNumeratorBits = hStream->GetBits(16);
+ if (!dwSharedIdBits)
+ return FALSE;
// Item 13: Skip Item 13 which has 16 bits.
hStream->SkipBits(16);
@@ -113,7 +125,7 @@ bool CPDF_HintTables::ReadPageHintTable(CFX_BitStream* hStream) {
return false;
const int nPages = GetNumberOfPages();
- if (nPages < 1)
+ if (nPages < 1 || nPages >= FPDF_PAGE_MAX_NUM)
return false;
const uint32_t dwPages = pdfium::base::checked_cast<uint32_t>(nPages);
@@ -136,13 +148,14 @@ bool CPDF_HintTables::ReadPageHintTable(CFX_BitStream* hStream) {
if (!CanReadFromBitStream(hStream, required_bits))
return false;
- CFX_ArrayTemplate<uint32_t> dwPageLenArray;
+ std::vector<uint32_t> dwPageLenArray;
for (int i = 0; i < nPages; ++i) {
FX_SAFE_UINT32 safePageLen = hStream->GetBits(dwDeltaPageLenBits);
safePageLen += dwPageLeastLen;
if (!safePageLen.IsValid())
return false;
- dwPageLenArray.Add(safePageLen.ValueOrDie());
+
+ dwPageLenArray.push_back(safePageLen.ValueOrDie());
}
int nOffsetE = GetEndOfFirstPageOffset();
diff --git a/core/fpdfapi/fpdf_parser/cpdf_hint_tables.h b/core/fpdfapi/fpdf_parser/cpdf_hint_tables.h
index 35fbdcb79b..cda0925de8 100644
--- a/core/fpdfapi/fpdf_parser/cpdf_hint_tables.h
+++ b/core/fpdfapi/fpdf_parser/cpdf_hint_tables.h
@@ -20,7 +20,7 @@ class CPDF_Stream;
class CPDF_HintTables {
public:
CPDF_HintTables(CPDF_DataAvail* pDataAvail, CPDF_Dictionary* pLinearized);
- ~CPDF_HintTables();
+ virtual ~CPDF_HintTables();
bool GetPagePos(int index,
FX_FILESIZE* szPageStartPos,
@@ -39,12 +39,13 @@ class CPDF_HintTables {
uint32_t GetItemLength(int index, const std::vector<FX_FILESIZE>& szArray);
private:
- int GetEndOfFirstPageOffset() const;
- int GetNumberOfPages() const;
- int GetFirstPageObjectNumber() const;
- int GetFirstPageNumber() const;
- int ReadPrimaryHintStreamOffset() const;
- int ReadPrimaryHintStreamLength() const;
+ // Tests can override.
+ virtual int GetEndOfFirstPageOffset() const;
+ virtual int GetNumberOfPages() const;
+ virtual int GetFirstPageObjectNumber() const;
+ virtual int GetFirstPageNumber() const;
+ virtual int ReadPrimaryHintStreamOffset() const;
+ virtual int ReadPrimaryHintStreamLength() const;
// Helper for the ReadPrimaryHintStream methods above.
int ReadPrimaryHintStream(int index) const;