summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
Diffstat (limited to 'core/src')
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp16
-rw-r--r--core/src/fpdfapi/fpdf_parser/fpdf_parser_parser_unittest.cpp18
2 files changed, 10 insertions, 24 deletions
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
index 5cc117798c..3696bb13db 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp
@@ -131,7 +131,9 @@ uint8_t CPDF_Parser::GetObjectType(FX_DWORD objnum) const {
}
uint16_t CPDF_Parser::GetObjectGenNum(FX_DWORD objnum) const {
- return m_ObjVersion[objnum];
+ ASSERT(IsValidObjectNumber(objnum));
+ auto it = m_ObjectInfo.find(objnum);
+ return it != m_ObjectInfo.end() ? it->second.gennum : 0;
}
bool CPDF_Parser::IsObjectFreeOrNull(FX_DWORD objnum) const {
@@ -179,7 +181,6 @@ void CPDF_Parser::CloseParser() {
m_SortedOffset.RemoveAll();
m_ObjectInfo.clear();
- m_ObjVersion.RemoveAll();
int32_t iLen = m_Trailers.GetSize();
for (int32_t i = 0; i < iLen; ++i) {
if (CPDF_Dictionary* trailer = m_Trailers.GetAt(i))
@@ -486,7 +487,7 @@ FX_BOOL CPDF_Parser::LoadLinearizedCrossRefV4(FX_FILESIZE pos,
if (version >= 1) {
m_bVersionUpdated = TRUE;
}
- m_ObjVersion.SetAtGrow(objnum, version);
+ m_ObjectInfo[objnum].gennum = version;
if (m_ObjectInfo[objnum].pos < m_Syntax.m_FileLen) {
void* pResult = FXSYS_bsearch(
&m_ObjectInfo[objnum].pos, m_SortedOffset.GetData(),
@@ -568,7 +569,7 @@ bool CPDF_Parser::LoadCrossRefV4(FX_FILESIZE pos,
if (version >= 1) {
m_bVersionUpdated = TRUE;
}
- m_ObjVersion.SetAtGrow(objnum, version);
+ m_ObjectInfo[objnum].gennum = version;
if (m_ObjectInfo[objnum].pos < m_Syntax.m_FileLen &&
!FindPosInOffsets(m_ObjectInfo[objnum].pos)) {
m_SortedOffset.Add(m_ObjectInfo[objnum].pos);
@@ -606,7 +607,6 @@ FX_BOOL CPDF_Parser::LoadAllCrossRefV5(FX_FILESIZE xrefpos) {
FX_BOOL CPDF_Parser::RebuildCrossRef() {
m_ObjectInfo.clear();
m_SortedOffset.RemoveAll();
- m_ObjVersion.RemoveAll();
if (m_pTrailer) {
m_pTrailer->Release();
m_pTrailer = NULL;
@@ -811,9 +811,9 @@ FX_BOOL CPDF_Parser::RebuildCrossRef() {
if (!m_ObjectInfo.empty() && IsValidObjectNumber(objnum) &&
m_ObjectInfo[objnum].pos) {
if (pObject) {
- FX_DWORD oldgen = m_ObjVersion.GetAt(objnum);
+ FX_DWORD oldgen = GetObjectGenNum(objnum);
m_ObjectInfo[objnum].pos = obj_pos;
- m_ObjVersion.SetAt(objnum, (int16_t)gennum);
+ m_ObjectInfo[objnum].gennum = gennum;
if (oldgen != gennum) {
m_bVersionUpdated = TRUE;
}
@@ -821,7 +821,7 @@ FX_BOOL CPDF_Parser::RebuildCrossRef() {
} else {
m_ObjectInfo[objnum].pos = obj_pos;
m_ObjectInfo[objnum].type = 1;
- m_ObjVersion.SetAtGrow(objnum, (int16_t)gennum);
+ m_ObjectInfo[objnum].gennum = gennum;
}
if (pObject) {
pObject->Release();
diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser_unittest.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser_unittest.cpp
index b39eb96785..77780b9dcf 100644
--- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser_unittest.cpp
+++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser_unittest.cpp
@@ -7,20 +7,6 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/utils/path_service.h"
-// Functions to help test an array's content against expected results.
-template <class TYPE>
-bool CompareArray(const CFX_ArrayTemplate<TYPE>& array1,
- const TYPE* array2,
- size_t size) {
- if (array1.GetSize() != size)
- return false;
-
- for (int i = 0; i < size; ++i)
- if (array1.GetAt(i) != array2[i])
- return false;
- return true;
-}
-
// Provide a way to read test data from a buffer instead of a file.
class CFX_TestBufferRead : public IFX_FileRead {
public:
@@ -257,8 +243,8 @@ TEST(fpdf_parser_parser, RebuildCrossRefCorrectly) {
const FX_WORD versions[] = {0, 0, 2, 4, 6, 8, 0};
for (size_t i = 0; i < FX_ArraySize(offsets); ++i)
EXPECT_EQ(offsets[i], parser.m_ObjectInfo[i].pos);
- ASSERT_TRUE(
- CompareArray(parser.m_ObjVersion, versions, FX_ArraySize(versions)));
+ for (size_t i = 0; i < FX_ArraySize(versions); ++i)
+ EXPECT_EQ(versions[i], parser.m_ObjectInfo[i].gennum);
}
TEST(fpdf_parser_parser, RebuildCrossRefFailed) {