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 25 matching lines...) Expand all Loading... |
36 HANDLER_ERROR | 36 HANDLER_ERROR |
37 }; | 37 }; |
38 | 38 |
39 // A limit on the maximum object number in the xref table. Theoretical limits | 39 // A limit on the maximum object number in the xref table. Theoretical limits |
40 // are higher, but this may be large enough in practice. | 40 // are higher, but this may be large enough in practice. |
41 static const uint32_t kMaxObjectNumber = 1048576; | 41 static const uint32_t kMaxObjectNumber = 1048576; |
42 | 42 |
43 CPDF_Parser(); | 43 CPDF_Parser(); |
44 ~CPDF_Parser(); | 44 ~CPDF_Parser(); |
45 | 45 |
46 Error StartParse(IFX_SeekableReadStream* pFile, CPDF_Document* pDocument); | 46 Error StartParse(const CFX_RetainPtr<IFX_SeekableReadStream>& pFile, |
47 Error StartLinearizedParse(IFX_SeekableReadStream* pFile, | 47 CPDF_Document* pDocument); |
| 48 Error StartLinearizedParse(const CFX_RetainPtr<IFX_SeekableReadStream>& pFile, |
48 CPDF_Document* pDocument); | 49 CPDF_Document* pDocument); |
49 | 50 |
50 void SetPassword(const FX_CHAR* password) { m_Password = password; } | 51 void SetPassword(const FX_CHAR* password) { m_Password = password; } |
51 CFX_ByteString GetPassword() { return m_Password; } | 52 CFX_ByteString GetPassword() { return m_Password; } |
52 CPDF_Dictionary* GetTrailer() const { return m_pTrailer.get(); } | 53 CPDF_Dictionary* GetTrailer() const { return m_pTrailer.get(); } |
53 FX_FILESIZE GetLastXRefOffset() const { return m_LastXRefOffset; } | 54 FX_FILESIZE GetLastXRefOffset() const { return m_LastXRefOffset; } |
54 | 55 |
55 uint32_t GetPermissions() const; | 56 uint32_t GetPermissions() const; |
56 uint32_t GetRootObjNum(); | 57 uint32_t GetRootObjNum(); |
57 uint32_t GetInfoObjNum(); | 58 uint32_t GetInfoObjNum(); |
58 CPDF_Array* GetIDArray(); | 59 CPDF_Array* GetIDArray(); |
59 | 60 |
60 CPDF_Dictionary* GetEncryptDict() const { return m_pEncryptDict; } | 61 CPDF_Dictionary* GetEncryptDict() const { return m_pEncryptDict; } |
61 | 62 |
62 std::unique_ptr<CPDF_Object> ParseIndirectObject( | 63 std::unique_ptr<CPDF_Object> ParseIndirectObject( |
63 CPDF_IndirectObjectHolder* pObjList, | 64 CPDF_IndirectObjectHolder* pObjList, |
64 uint32_t objnum); | 65 uint32_t objnum); |
65 | 66 |
66 uint32_t GetLastObjNum() const; | 67 uint32_t GetLastObjNum() const; |
67 bool IsValidObjectNumber(uint32_t objnum) const; | 68 bool IsValidObjectNumber(uint32_t objnum) const; |
68 FX_FILESIZE GetObjectPositionOrZero(uint32_t objnum) const; | 69 FX_FILESIZE GetObjectPositionOrZero(uint32_t objnum) const; |
69 uint8_t GetObjectType(uint32_t objnum) const; | 70 uint8_t GetObjectType(uint32_t objnum) const; |
70 uint16_t GetObjectGenNum(uint32_t objnum) const; | 71 uint16_t GetObjectGenNum(uint32_t objnum) const; |
71 bool IsVersionUpdated() const { return m_bVersionUpdated; } | 72 bool IsVersionUpdated() const { return m_bVersionUpdated; } |
72 bool IsObjectFreeOrNull(uint32_t objnum) const; | 73 bool IsObjectFreeOrNull(uint32_t objnum) const; |
73 CPDF_CryptoHandler* GetCryptoHandler(); | 74 CPDF_CryptoHandler* GetCryptoHandler(); |
74 IFX_SeekableReadStream* GetFileAccess() const; | 75 CFX_RetainPtr<IFX_SeekableReadStream> GetFileAccess() const; |
75 | 76 |
76 FX_FILESIZE GetObjectOffset(uint32_t objnum) const; | 77 FX_FILESIZE GetObjectOffset(uint32_t objnum) const; |
77 FX_FILESIZE GetObjectSize(uint32_t objnum) const; | 78 FX_FILESIZE GetObjectSize(uint32_t objnum) const; |
78 | 79 |
79 void GetIndirectBinary(uint32_t objnum, uint8_t*& pBuffer, uint32_t& size); | 80 void GetIndirectBinary(uint32_t objnum, uint8_t*& pBuffer, uint32_t& size); |
80 int GetFileVersion() const { return m_FileVersion; } | 81 int GetFileVersion() const { return m_FileVersion; } |
81 bool IsXRefStream() const { return m_bXRefStream; } | 82 bool IsXRefStream() const { return m_bXRefStream; } |
82 | 83 |
83 std::unique_ptr<CPDF_Object> ParseIndirectObjectAt( | 84 std::unique_ptr<CPDF_Object> ParseIndirectObjectAt( |
84 CPDF_IndirectObjectHolder* pObjList, | 85 CPDF_IndirectObjectHolder* pObjList, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 bool LoadAllCrossRefV5(FX_FILESIZE pos); | 134 bool LoadAllCrossRefV5(FX_FILESIZE pos); |
134 bool LoadCrossRefV5(FX_FILESIZE* pos, bool bMainXRef); | 135 bool LoadCrossRefV5(FX_FILESIZE* pos, bool bMainXRef); |
135 std::unique_ptr<CPDF_Dictionary> LoadTrailerV4(); | 136 std::unique_ptr<CPDF_Dictionary> LoadTrailerV4(); |
136 Error SetEncryptHandler(); | 137 Error SetEncryptHandler(); |
137 void ReleaseEncryptHandler(); | 138 void ReleaseEncryptHandler(); |
138 bool LoadLinearizedAllCrossRefV4(FX_FILESIZE pos, uint32_t dwObjCount); | 139 bool LoadLinearizedAllCrossRefV4(FX_FILESIZE pos, uint32_t dwObjCount); |
139 bool LoadLinearizedCrossRefV4(FX_FILESIZE pos, uint32_t dwObjCount); | 140 bool LoadLinearizedCrossRefV4(FX_FILESIZE pos, uint32_t dwObjCount); |
140 bool LoadLinearizedAllCrossRefV5(FX_FILESIZE pos); | 141 bool LoadLinearizedAllCrossRefV5(FX_FILESIZE pos); |
141 Error LoadLinearizedMainXRefTable(); | 142 Error LoadLinearizedMainXRefTable(); |
142 CPDF_StreamAcc* GetObjectStream(uint32_t number); | 143 CPDF_StreamAcc* GetObjectStream(uint32_t number); |
143 bool IsLinearizedFile(IFX_SeekableReadStream* pFileAccess, uint32_t offset); | 144 bool IsLinearizedFile( |
| 145 const CFX_RetainPtr<IFX_SeekableReadStream>& pFileAccess, |
| 146 uint32_t offset); |
144 void SetEncryptDictionary(CPDF_Dictionary* pDict); | 147 void SetEncryptDictionary(CPDF_Dictionary* pDict); |
145 void ShrinkObjectMap(uint32_t size); | 148 void ShrinkObjectMap(uint32_t size); |
146 // A simple check whether the cross reference table matches with | 149 // A simple check whether the cross reference table matches with |
147 // the objects. | 150 // the objects. |
148 bool VerifyCrossRefV4(); | 151 bool VerifyCrossRefV4(); |
149 | 152 |
150 CPDF_Document* m_pDocument; // not owned | 153 CPDF_Document* m_pDocument; // not owned |
151 bool m_bHasParsed; | 154 bool m_bHasParsed; |
152 bool m_bOwnFileRead; | |
153 bool m_bXRefStream; | 155 bool m_bXRefStream; |
154 bool m_bVersionUpdated; | 156 bool m_bVersionUpdated; |
155 int m_FileVersion; | 157 int m_FileVersion; |
156 CPDF_Dictionary* m_pEncryptDict; | 158 CPDF_Dictionary* m_pEncryptDict; |
157 FX_FILESIZE m_LastXRefOffset; | 159 FX_FILESIZE m_LastXRefOffset; |
158 std::unique_ptr<CPDF_SecurityHandler> m_pSecurityHandler; | 160 std::unique_ptr<CPDF_SecurityHandler> m_pSecurityHandler; |
159 CFX_ByteString m_Password; | 161 CFX_ByteString m_Password; |
160 std::set<FX_FILESIZE> m_SortedOffset; | 162 std::set<FX_FILESIZE> m_SortedOffset; |
161 std::unique_ptr<CPDF_Dictionary> m_pTrailer; | 163 std::unique_ptr<CPDF_Dictionary> m_pTrailer; |
162 std::vector<std::unique_ptr<CPDF_Dictionary>> m_Trailers; | 164 std::vector<std::unique_ptr<CPDF_Dictionary>> m_Trailers; |
163 std::unique_ptr<CPDF_LinearizedHeader> m_pLinearized; | 165 std::unique_ptr<CPDF_LinearizedHeader> m_pLinearized; |
164 uint32_t m_dwXrefStartObjNum; | 166 uint32_t m_dwXrefStartObjNum; |
165 | 167 |
166 // A map of object numbers to indirect streams. Map owns the streams. | 168 // A map of object numbers to indirect streams. Map owns the streams. |
167 std::map<uint32_t, std::unique_ptr<CPDF_StreamAcc>> m_ObjectStreamMap; | 169 std::map<uint32_t, std::unique_ptr<CPDF_StreamAcc>> m_ObjectStreamMap; |
168 | 170 |
169 // Mapping of object numbers to offsets. The offsets are relative to the first | 171 // Mapping of object numbers to offsets. The offsets are relative to the first |
170 // object in the stream. | 172 // object in the stream. |
171 using StreamObjectCache = std::map<uint32_t, uint32_t>; | 173 using StreamObjectCache = std::map<uint32_t, uint32_t>; |
172 | 174 |
173 // Mapping of streams to their object caches. This is valid as long as the | 175 // Mapping of streams to their object caches. This is valid as long as the |
174 // streams in |m_ObjectStreamMap| are valid. | 176 // streams in |m_ObjectStreamMap| are valid. |
175 std::map<CPDF_StreamAcc*, StreamObjectCache> m_ObjCache; | 177 std::map<CPDF_StreamAcc*, StreamObjectCache> m_ObjCache; |
176 | 178 |
177 // All indirect object numbers that are being parsed. | 179 // All indirect object numbers that are being parsed. |
178 std::set<uint32_t> m_ParsingObjNums; | 180 std::set<uint32_t> m_ParsingObjNums; |
179 }; | 181 }; |
180 | 182 |
181 #endif // CORE_FPDFAPI_PARSER_CPDF_PARSER_H_ | 183 #endif // CORE_FPDFAPI_PARSER_CPDF_PARSER_H_ |
OLD | NEW |