OLD | NEW |
1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #ifndef CORE_FPDFAPI_PARSER_CPDF_PARSER_H_ | 7 #ifndef CORE_FPDFAPI_PARSER_CPDF_PARSER_H_ |
8 #define CORE_FPDFAPI_PARSER_CPDF_PARSER_H_ | 8 #define CORE_FPDFAPI_PARSER_CPDF_PARSER_H_ |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 bool IsVersionUpdated() const { return m_bVersionUpdated; } | 69 bool IsVersionUpdated() const { return m_bVersionUpdated; } |
70 bool IsObjectFreeOrNull(uint32_t objnum) const; | 70 bool IsObjectFreeOrNull(uint32_t objnum) const; |
71 CPDF_CryptoHandler* GetCryptoHandler(); | 71 CPDF_CryptoHandler* GetCryptoHandler(); |
72 IFX_SeekableReadStream* GetFileAccess() const; | 72 IFX_SeekableReadStream* GetFileAccess() const; |
73 | 73 |
74 FX_FILESIZE GetObjectOffset(uint32_t objnum) const; | 74 FX_FILESIZE GetObjectOffset(uint32_t objnum) const; |
75 FX_FILESIZE GetObjectSize(uint32_t objnum) const; | 75 FX_FILESIZE GetObjectSize(uint32_t objnum) const; |
76 | 76 |
77 void GetIndirectBinary(uint32_t objnum, uint8_t*& pBuffer, uint32_t& size); | 77 void GetIndirectBinary(uint32_t objnum, uint8_t*& pBuffer, uint32_t& size); |
78 int GetFileVersion() const { return m_FileVersion; } | 78 int GetFileVersion() const { return m_FileVersion; } |
79 FX_BOOL IsXRefStream() const { return m_bXRefStream; } | 79 bool IsXRefStream() const { return m_bXRefStream; } |
80 | 80 |
81 CPDF_Object* ParseIndirectObjectAt(CPDF_IndirectObjectHolder* pObjList, | 81 CPDF_Object* ParseIndirectObjectAt(CPDF_IndirectObjectHolder* pObjList, |
82 FX_FILESIZE pos, | 82 FX_FILESIZE pos, |
83 uint32_t objnum); | 83 uint32_t objnum); |
84 | 84 |
85 CPDF_Object* ParseIndirectObjectAtByStrict( | 85 CPDF_Object* ParseIndirectObjectAtByStrict( |
86 CPDF_IndirectObjectHolder* pObjList, | 86 CPDF_IndirectObjectHolder* pObjList, |
87 FX_FILESIZE pos, | 87 FX_FILESIZE pos, |
88 uint32_t objnum, | 88 uint32_t objnum, |
89 FX_FILESIZE* pResultPos); | 89 FX_FILESIZE* pResultPos); |
90 | 90 |
91 uint32_t GetFirstPageNo() const { return m_dwFirstPageNo; } | 91 uint32_t GetFirstPageNo() const { return m_dwFirstPageNo; } |
92 | 92 |
93 protected: | 93 protected: |
94 struct ObjectInfo { | 94 struct ObjectInfo { |
95 ObjectInfo() : pos(0), type(0), gennum(0) {} | 95 ObjectInfo() : pos(0), type(0), gennum(0) {} |
96 | 96 |
97 FX_FILESIZE pos; | 97 FX_FILESIZE pos; |
98 uint8_t type; | 98 uint8_t type; |
99 uint16_t gennum; | 99 uint16_t gennum; |
100 }; | 100 }; |
101 | 101 |
102 std::unique_ptr<CPDF_SyntaxParser> m_pSyntax; | 102 std::unique_ptr<CPDF_SyntaxParser> m_pSyntax; |
103 std::map<uint32_t, ObjectInfo> m_ObjectInfo; | 103 std::map<uint32_t, ObjectInfo> m_ObjectInfo; |
104 | 104 |
105 bool LoadCrossRefV4(FX_FILESIZE pos, FX_FILESIZE streampos, FX_BOOL bSkip); | 105 bool LoadCrossRefV4(FX_FILESIZE pos, FX_FILESIZE streampos, bool bSkip); |
106 FX_BOOL RebuildCrossRef(); | 106 bool RebuildCrossRef(); |
107 | 107 |
108 private: | 108 private: |
109 friend class CPDF_DataAvail; | 109 friend class CPDF_DataAvail; |
110 | 110 |
111 enum class ParserState { | 111 enum class ParserState { |
112 kDefault, | 112 kDefault, |
113 kComment, | 113 kComment, |
114 kWhitespace, | 114 kWhitespace, |
115 kString, | 115 kString, |
116 kHexString, | 116 kHexString, |
117 kEscapedString, | 117 kEscapedString, |
118 kXref, | 118 kXref, |
119 kObjNum, | 119 kObjNum, |
120 kPostObjNum, | 120 kPostObjNum, |
121 kGenNum, | 121 kGenNum, |
122 kPostGenNum, | 122 kPostGenNum, |
123 kTrailer, | 123 kTrailer, |
124 kBeginObj, | 124 kBeginObj, |
125 kEndObj | 125 kEndObj |
126 }; | 126 }; |
127 | 127 |
128 CPDF_Object* ParseDirect(CPDF_Object* pObj); | 128 CPDF_Object* ParseDirect(CPDF_Object* pObj); |
129 FX_BOOL LoadAllCrossRefV4(FX_FILESIZE pos); | 129 bool LoadAllCrossRefV4(FX_FILESIZE pos); |
130 FX_BOOL LoadAllCrossRefV5(FX_FILESIZE pos); | 130 bool LoadAllCrossRefV5(FX_FILESIZE pos); |
131 FX_BOOL LoadCrossRefV5(FX_FILESIZE* pos, FX_BOOL bMainXRef); | 131 bool LoadCrossRefV5(FX_FILESIZE* pos, bool bMainXRef); |
132 CPDF_Dictionary* LoadTrailerV4(); | 132 CPDF_Dictionary* LoadTrailerV4(); |
133 Error SetEncryptHandler(); | 133 Error SetEncryptHandler(); |
134 void ReleaseEncryptHandler(); | 134 void ReleaseEncryptHandler(); |
135 FX_BOOL LoadLinearizedAllCrossRefV4(FX_FILESIZE pos, uint32_t dwObjCount); | 135 bool LoadLinearizedAllCrossRefV4(FX_FILESIZE pos, uint32_t dwObjCount); |
136 FX_BOOL LoadLinearizedCrossRefV4(FX_FILESIZE pos, uint32_t dwObjCount); | 136 bool LoadLinearizedCrossRefV4(FX_FILESIZE pos, uint32_t dwObjCount); |
137 FX_BOOL LoadLinearizedAllCrossRefV5(FX_FILESIZE pos); | 137 bool LoadLinearizedAllCrossRefV5(FX_FILESIZE pos); |
138 Error LoadLinearizedMainXRefTable(); | 138 Error LoadLinearizedMainXRefTable(); |
139 CPDF_StreamAcc* GetObjectStream(uint32_t number); | 139 CPDF_StreamAcc* GetObjectStream(uint32_t number); |
140 FX_BOOL IsLinearizedFile(IFX_SeekableReadStream* pFileAccess, | 140 bool IsLinearizedFile(IFX_SeekableReadStream* pFileAccess, uint32_t offset); |
141 uint32_t offset); | |
142 void SetEncryptDictionary(CPDF_Dictionary* pDict); | 141 void SetEncryptDictionary(CPDF_Dictionary* pDict); |
143 void ShrinkObjectMap(uint32_t size); | 142 void ShrinkObjectMap(uint32_t size); |
144 // A simple check whether the cross reference table matches with | 143 // A simple check whether the cross reference table matches with |
145 // the objects. | 144 // the objects. |
146 bool VerifyCrossRefV4(); | 145 bool VerifyCrossRefV4(); |
147 | 146 |
148 CPDF_Document* m_pDocument; // not owned | 147 CPDF_Document* m_pDocument; // not owned |
149 bool m_bHasParsed; | 148 bool m_bHasParsed; |
150 bool m_bOwnFileRead; | 149 bool m_bOwnFileRead; |
151 int m_FileVersion; | 150 int m_FileVersion; |
152 CPDF_Dictionary* m_pTrailer; | 151 CPDF_Dictionary* m_pTrailer; |
153 CPDF_Dictionary* m_pEncryptDict; | 152 CPDF_Dictionary* m_pEncryptDict; |
154 FX_FILESIZE m_LastXRefOffset; | 153 FX_FILESIZE m_LastXRefOffset; |
155 FX_BOOL m_bXRefStream; | 154 bool m_bXRefStream; |
156 std::unique_ptr<CPDF_SecurityHandler> m_pSecurityHandler; | 155 std::unique_ptr<CPDF_SecurityHandler> m_pSecurityHandler; |
157 CFX_ByteString m_Password; | 156 CFX_ByteString m_Password; |
158 std::set<FX_FILESIZE> m_SortedOffset; | 157 std::set<FX_FILESIZE> m_SortedOffset; |
159 std::vector<CPDF_Dictionary*> m_Trailers; | 158 std::vector<CPDF_Dictionary*> m_Trailers; |
160 bool m_bVersionUpdated; | 159 bool m_bVersionUpdated; |
161 CPDF_Object* m_pLinearized; | 160 CPDF_Object* m_pLinearized; |
162 uint32_t m_dwFirstPageNo; | 161 uint32_t m_dwFirstPageNo; |
163 uint32_t m_dwXrefStartObjNum; | 162 uint32_t m_dwXrefStartObjNum; |
164 | 163 |
165 // A map of object numbers to indirect streams. Map owns the streams. | 164 // A map of object numbers to indirect streams. Map owns the streams. |
166 std::map<uint32_t, std::unique_ptr<CPDF_StreamAcc>> m_ObjectStreamMap; | 165 std::map<uint32_t, std::unique_ptr<CPDF_StreamAcc>> m_ObjectStreamMap; |
167 | 166 |
168 // Mapping of object numbers to offsets. The offsets are relative to the first | 167 // Mapping of object numbers to offsets. The offsets are relative to the first |
169 // object in the stream. | 168 // object in the stream. |
170 using StreamObjectCache = std::map<uint32_t, uint32_t>; | 169 using StreamObjectCache = std::map<uint32_t, uint32_t>; |
171 | 170 |
172 // Mapping of streams to their object caches. This is valid as long as the | 171 // Mapping of streams to their object caches. This is valid as long as the |
173 // streams in |m_ObjectStreamMap| are valid. | 172 // streams in |m_ObjectStreamMap| are valid. |
174 std::map<CPDF_StreamAcc*, StreamObjectCache> m_ObjCache; | 173 std::map<CPDF_StreamAcc*, StreamObjectCache> m_ObjCache; |
175 | 174 |
176 // All indirect object numbers that are being parsed. | 175 // All indirect object numbers that are being parsed. |
177 std::set<uint32_t> m_ParsingObjNums; | 176 std::set<uint32_t> m_ParsingObjNums; |
178 }; | 177 }; |
179 | 178 |
180 #endif // CORE_FPDFAPI_PARSER_CPDF_PARSER_H_ | 179 #endif // CORE_FPDFAPI_PARSER_CPDF_PARSER_H_ |
OLD | NEW |