summaryrefslogtreecommitdiff
path: root/core/fpdfapi/parser
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfapi/parser')
-rw-r--r--core/fpdfapi/parser/cpdf_parser.cpp32
-rw-r--r--core/fpdfapi/parser/cpdf_parser.h20
-rw-r--r--core/fpdfapi/parser/cpdf_parser_unittest.cpp86
3 files changed, 73 insertions, 65 deletions
diff --git a/core/fpdfapi/parser/cpdf_parser.cpp b/core/fpdfapi/parser/cpdf_parser.cpp
index 40d1b49ed6..336e6625b5 100644
--- a/core/fpdfapi/parser/cpdf_parser.cpp
+++ b/core/fpdfapi/parser/cpdf_parser.cpp
@@ -52,20 +52,6 @@ int32_t GetStreamFirst(const RetainPtr<CPDF_StreamAcc>& pObjStream) {
return pObjStream->GetDict()->GetIntegerFor("First");
}
-CPDF_Parser::ObjectType GetObjectTypeFromCrossRefStreamType(
- int cross_ref_stream_type) {
- switch (cross_ref_stream_type) {
- case 0:
- return CPDF_Parser::ObjectType::kFree;
- case 1:
- return CPDF_Parser::ObjectType::kNotCompressed;
- case 2:
- return CPDF_Parser::ObjectType::kCompressed;
- default:
- return CPDF_Parser::ObjectType::kNull;
- }
-}
-
} // namespace
class CPDF_Parser::TrailerData {
@@ -161,6 +147,10 @@ bool CPDF_Parser::IsObjectFreeOrNull(uint32_t objnum) const {
return false;
}
+bool CPDF_Parser::IsObjectFree(uint32_t objnum) const {
+ return GetObjectType(objnum) == ObjectType::kFree;
+}
+
void CPDF_Parser::SetEncryptDictionary(CPDF_Dictionary* pDict) {
m_pEncryptDict = pDict;
}
@@ -1486,3 +1476,17 @@ CPDF_Parser::Error CPDF_Parser::LoadLinearizedMainXRefTable() {
return SUCCESS;
}
+
+CPDF_Parser::ObjectType CPDF_Parser::GetObjectTypeFromCrossRefStreamType(
+ int cross_ref_stream_type) const {
+ switch (cross_ref_stream_type) {
+ case 0:
+ return CPDF_Parser::ObjectType::kFree;
+ case 1:
+ return CPDF_Parser::ObjectType::kNotCompressed;
+ case 2:
+ return CPDF_Parser::ObjectType::kCompressed;
+ default:
+ return CPDF_Parser::ObjectType::kNull;
+ }
+}
diff --git a/core/fpdfapi/parser/cpdf_parser.h b/core/fpdfapi/parser/cpdf_parser.h
index 75d58e2e40..5114ee6ba3 100644
--- a/core/fpdfapi/parser/cpdf_parser.h
+++ b/core/fpdfapi/parser/cpdf_parser.h
@@ -41,13 +41,6 @@ class CPDF_Parser {
HANDLER_ERROR
};
- enum class ObjectType : uint8_t {
- kFree = 0x00,
- kNotCompressed = 0x01,
- kCompressed = 0x02,
- kNull = 0xFF,
- };
-
// A limit on the maximum object number in the xref table. Theoretical limits
// are higher, but this may be large enough in practice.
static const uint32_t kMaxObjectNumber = 1048576;
@@ -81,11 +74,11 @@ class CPDF_Parser {
uint32_t GetLastObjNum() const;
bool IsValidObjectNumber(uint32_t objnum) const;
FX_FILESIZE GetObjectPositionOrZero(uint32_t objnum) const;
- ObjectType GetObjectType(uint32_t objnum) const;
uint16_t GetObjectGenNum(uint32_t objnum) const;
bool IsObjectFreeOrNull(uint32_t objnum) const;
RetainPtr<CPDF_CryptoHandler> GetCryptoHandler() const;
RetainPtr<IFX_SeekableReadStream> GetFileAccess() const;
+ bool IsObjectFree(uint32_t objnum) const;
FX_FILESIZE GetObjectOffset(uint32_t objnum) const;
@@ -106,6 +99,13 @@ class CPDF_Parser {
uint32_t GetFirstPageNo() const;
protected:
+ enum class ObjectType : uint8_t {
+ kFree = 0x00,
+ kNotCompressed = 0x01,
+ kCompressed = 0x02,
+ kNull = 0xFF,
+ };
+
struct ObjectInfo {
ObjectInfo() : pos(0), type(ObjectType::kFree), gennum(0) {}
// if type is ObjectType::kCompressed the archive_obj_num should be used.
@@ -192,6 +192,10 @@ class CPDF_Parser {
bool ParseFileVersion();
UnownedPtr<CPDF_Document> m_pDocument;
+ ObjectType GetObjectType(uint32_t objnum) const;
+ ObjectType GetObjectTypeFromCrossRefStreamType(
+ int cross_ref_stream_type) const;
+
bool m_bHasParsed;
bool m_bXRefStream;
int m_FileVersion;
diff --git a/core/fpdfapi/parser/cpdf_parser_unittest.cpp b/core/fpdfapi/parser/cpdf_parser_unittest.cpp
index 53e1434141..555c35c7cb 100644
--- a/core/fpdfapi/parser/cpdf_parser_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_parser_unittest.cpp
@@ -94,13 +94,13 @@ TEST(cpdf_parser, LoadCrossRefV4) {
ASSERT_TRUE(parser.LoadCrossRefV4(0, false));
const FX_FILESIZE offsets[] = {0, 17, 81, 0, 331, 409};
- const CPDF_Parser::ObjectType types[] = {
- CPDF_Parser::ObjectType::kFree,
- CPDF_Parser::ObjectType::kNotCompressed,
- CPDF_Parser::ObjectType::kNotCompressed,
- CPDF_Parser::ObjectType::kFree,
- CPDF_Parser::ObjectType::kNotCompressed,
- CPDF_Parser::ObjectType::kNotCompressed};
+ const CPDF_TestParser::ObjectType types[] = {
+ CPDF_TestParser::ObjectType::kFree,
+ CPDF_TestParser::ObjectType::kNotCompressed,
+ CPDF_TestParser::ObjectType::kNotCompressed,
+ CPDF_TestParser::ObjectType::kFree,
+ CPDF_TestParser::ObjectType::kNotCompressed,
+ CPDF_TestParser::ObjectType::kNotCompressed};
for (size_t i = 0; i < FX_ArraySize(offsets); ++i) {
EXPECT_EQ(offsets[i], parser.m_ObjectInfo[i].pos);
EXPECT_EQ(types[i], parser.m_ObjectInfo[i].type);
@@ -126,20 +126,20 @@ TEST(cpdf_parser, LoadCrossRefV4) {
ASSERT_TRUE(parser.LoadCrossRefV4(0, false));
const FX_FILESIZE offsets[] = {0, 0, 0, 25325, 0, 0, 0,
0, 25518, 25635, 0, 0, 25777};
- const CPDF_Parser::ObjectType types[] = {
- CPDF_Parser::ObjectType::kFree,
- CPDF_Parser::ObjectType::kFree,
- CPDF_Parser::ObjectType::kFree,
- CPDF_Parser::ObjectType::kNotCompressed,
- CPDF_Parser::ObjectType::kFree,
- CPDF_Parser::ObjectType::kFree,
- CPDF_Parser::ObjectType::kFree,
- CPDF_Parser::ObjectType::kFree,
- CPDF_Parser::ObjectType::kNotCompressed,
- CPDF_Parser::ObjectType::kNotCompressed,
- CPDF_Parser::ObjectType::kFree,
- CPDF_Parser::ObjectType::kFree,
- CPDF_Parser::ObjectType::kNotCompressed};
+ const CPDF_TestParser::ObjectType types[] = {
+ CPDF_TestParser::ObjectType::kFree,
+ CPDF_TestParser::ObjectType::kFree,
+ CPDF_TestParser::ObjectType::kFree,
+ CPDF_TestParser::ObjectType::kNotCompressed,
+ CPDF_TestParser::ObjectType::kFree,
+ CPDF_TestParser::ObjectType::kFree,
+ CPDF_TestParser::ObjectType::kFree,
+ CPDF_TestParser::ObjectType::kFree,
+ CPDF_TestParser::ObjectType::kNotCompressed,
+ CPDF_TestParser::ObjectType::kNotCompressed,
+ CPDF_TestParser::ObjectType::kFree,
+ CPDF_TestParser::ObjectType::kFree,
+ CPDF_TestParser::ObjectType::kNotCompressed};
for (size_t i = 0; i < FX_ArraySize(offsets); ++i) {
EXPECT_EQ(offsets[i], parser.m_ObjectInfo[i].pos);
EXPECT_EQ(types[i], parser.m_ObjectInfo[i].type);
@@ -165,20 +165,20 @@ TEST(cpdf_parser, LoadCrossRefV4) {
ASSERT_TRUE(parser.LoadCrossRefV4(0, false));
const FX_FILESIZE offsets[] = {0, 0, 0, 25325, 0, 0, 0,
0, 0, 25635, 0, 0, 25777};
- const CPDF_Parser::ObjectType types[] = {
- CPDF_Parser::ObjectType::kFree,
- CPDF_Parser::ObjectType::kFree,
- CPDF_Parser::ObjectType::kFree,
- CPDF_Parser::ObjectType::kNotCompressed,
- CPDF_Parser::ObjectType::kFree,
- CPDF_Parser::ObjectType::kFree,
- CPDF_Parser::ObjectType::kFree,
- CPDF_Parser::ObjectType::kFree,
- CPDF_Parser::ObjectType::kFree,
- CPDF_Parser::ObjectType::kNotCompressed,
- CPDF_Parser::ObjectType::kFree,
- CPDF_Parser::ObjectType::kFree,
- CPDF_Parser::ObjectType::kNotCompressed};
+ const CPDF_TestParser::ObjectType types[] = {
+ CPDF_TestParser::ObjectType::kFree,
+ CPDF_TestParser::ObjectType::kFree,
+ CPDF_TestParser::ObjectType::kFree,
+ CPDF_TestParser::ObjectType::kNotCompressed,
+ CPDF_TestParser::ObjectType::kFree,
+ CPDF_TestParser::ObjectType::kFree,
+ CPDF_TestParser::ObjectType::kFree,
+ CPDF_TestParser::ObjectType::kFree,
+ CPDF_TestParser::ObjectType::kFree,
+ CPDF_TestParser::ObjectType::kNotCompressed,
+ CPDF_TestParser::ObjectType::kFree,
+ CPDF_TestParser::ObjectType::kFree,
+ CPDF_TestParser::ObjectType::kNotCompressed};
for (size_t i = 0; i < FX_ArraySize(offsets); ++i) {
EXPECT_EQ(offsets[i], parser.m_ObjectInfo[i].pos);
EXPECT_EQ(types[i], parser.m_ObjectInfo[i].type);
@@ -202,14 +202,14 @@ TEST(cpdf_parser, LoadCrossRefV4) {
ASSERT_TRUE(parser.LoadCrossRefV4(0, false));
const FX_FILESIZE offsets[] = {0, 23, 0, 0, 0, 45, 179};
- const CPDF_Parser::ObjectType types[] = {
- CPDF_Parser::ObjectType::kFree,
- CPDF_Parser::ObjectType::kNotCompressed,
- CPDF_Parser::ObjectType::kFree,
- CPDF_Parser::ObjectType::kFree,
- CPDF_Parser::ObjectType::kFree,
- CPDF_Parser::ObjectType::kNotCompressed,
- CPDF_Parser::ObjectType::kNotCompressed};
+ const CPDF_TestParser::ObjectType types[] = {
+ CPDF_TestParser::ObjectType::kFree,
+ CPDF_TestParser::ObjectType::kNotCompressed,
+ CPDF_TestParser::ObjectType::kFree,
+ CPDF_TestParser::ObjectType::kFree,
+ CPDF_TestParser::ObjectType::kFree,
+ CPDF_TestParser::ObjectType::kNotCompressed,
+ CPDF_TestParser::ObjectType::kNotCompressed};
for (size_t i = 0; i < FX_ArraySize(offsets); ++i) {
EXPECT_EQ(offsets[i], parser.m_ObjectInfo[i].pos);
EXPECT_EQ(types[i], parser.m_ObjectInfo[i].type);