Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(940)

Side by Side Diff: core/fpdfapi/parser/cpdf_syntax_parser.h

Issue 2479303002: Use unique_ptr return from CPDF_Parser::ParseIndirectObject() (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_SYNTAX_PARSER_H_ 7 #ifndef CORE_FPDFAPI_PARSER_CPDF_SYNTAX_PARSER_H_
8 #define CORE_FPDFAPI_PARSER_CPDF_SYNTAX_PARSER_H_ 8 #define CORE_FPDFAPI_PARSER_CPDF_SYNTAX_PARSER_H_
9 9
10 #include <memory> 10 #include <memory>
11 11
12 #include "core/fxcrt/cfx_string_pool_template.h" 12 #include "core/fxcrt/cfx_string_pool_template.h"
13 #include "core/fxcrt/cfx_weak_ptr.h" 13 #include "core/fxcrt/cfx_weak_ptr.h"
14 #include "core/fxcrt/fx_basic.h" 14 #include "core/fxcrt/fx_basic.h"
15 15
16 class CPDF_CryptoHandler; 16 class CPDF_CryptoHandler;
17 class CPDF_Dictionary; 17 class CPDF_Dictionary;
18 class CPDF_IndirectObjectHolder; 18 class CPDF_IndirectObjectHolder;
19 class CPDF_Object; 19 class CPDF_Object;
20 class CPDF_Stream; 20 class CPDF_Stream;
21 class IFX_SeekableReadStream; 21 class IFX_SeekableReadStream;
22 22
23 class CPDF_SyntaxParser { 23 class CPDF_SyntaxParser {
24 public: 24 public:
25 CPDF_SyntaxParser(); 25 CPDF_SyntaxParser();
26 explicit CPDF_SyntaxParser(const CFX_WeakPtr<CFX_ByteStringPool>& pPool); 26 explicit CPDF_SyntaxParser(const CFX_WeakPtr<CFX_ByteStringPool>& pPool);
27 ~CPDF_SyntaxParser(); 27 ~CPDF_SyntaxParser();
28 28
29 void InitParser(IFX_SeekableReadStream* pFileAccess, uint32_t HeaderOffset); 29 void InitParser(IFX_SeekableReadStream* pFileAccess, uint32_t HeaderOffset);
30
31 FX_FILESIZE SavePos() const { return m_Pos; } 30 FX_FILESIZE SavePos() const { return m_Pos; }
32 void RestorePos(FX_FILESIZE pos) { m_Pos = pos; } 31 void RestorePos(FX_FILESIZE pos) { m_Pos = pos; }
33 32
34 CPDF_Object* GetObject(CPDF_IndirectObjectHolder* pObjList, 33 std::unique_ptr<CPDF_Object> GetObject(CPDF_IndirectObjectHolder* pObjList,
35 uint32_t objnum, 34 uint32_t objnum,
36 uint32_t gennum, 35 uint32_t gennum,
37 bool bDecrypt); 36 bool bDecrypt);
38 CPDF_Object* GetObjectForStrict(CPDF_IndirectObjectHolder* pObjList, 37
39 uint32_t objnum, 38 std::unique_ptr<CPDF_Object> GetObjectForStrict(
40 uint32_t gennum); 39 CPDF_IndirectObjectHolder* pObjList,
40 uint32_t objnum,
41 uint32_t gennum);
42
41 CFX_ByteString GetKeyword(); 43 CFX_ByteString GetKeyword();
42
43 void ToNextLine(); 44 void ToNextLine();
44 void ToNextWord(); 45 void ToNextWord();
45
46 bool SearchWord(const CFX_ByteStringC& word, 46 bool SearchWord(const CFX_ByteStringC& word,
47 bool bWholeWord, 47 bool bWholeWord,
48 bool bForward, 48 bool bForward,
49 FX_FILESIZE limit); 49 FX_FILESIZE limit);
50
50 FX_FILESIZE FindTag(const CFX_ByteStringC& tag, FX_FILESIZE limit); 51 FX_FILESIZE FindTag(const CFX_ByteStringC& tag, FX_FILESIZE limit);
51
52 void SetEncrypt(std::unique_ptr<CPDF_CryptoHandler> pCryptoHandler); 52 void SetEncrypt(std::unique_ptr<CPDF_CryptoHandler> pCryptoHandler);
53
54 bool ReadBlock(uint8_t* pBuf, uint32_t size); 53 bool ReadBlock(uint8_t* pBuf, uint32_t size);
55 bool GetCharAt(FX_FILESIZE pos, uint8_t& ch); 54 bool GetCharAt(FX_FILESIZE pos, uint8_t& ch);
56 CFX_ByteString GetNextWord(bool* bIsNumber); 55 CFX_ByteString GetNextWord(bool* bIsNumber);
57 56
58 private: 57 private:
59 friend class CPDF_Parser; 58 friend class CPDF_Parser;
60 friend class CPDF_DataAvail; 59 friend class CPDF_DataAvail;
61 friend class cpdf_syntax_parser_ReadHexString_Test; 60 friend class cpdf_syntax_parser_ReadHexString_Test;
62 61
63 static const int kParserMaxRecursionDepth = 64; 62 static const int kParserMaxRecursionDepth = 64;
64 static int s_CurrentRecursionDepth; 63 static int s_CurrentRecursionDepth;
65 64
66 uint32_t GetDirectNum(); 65 uint32_t GetDirectNum();
67 bool ReadChar(FX_FILESIZE read_pos, uint32_t read_size); 66 bool ReadChar(FX_FILESIZE read_pos, uint32_t read_size);
68 bool GetNextChar(uint8_t& ch); 67 bool GetNextChar(uint8_t& ch);
69 bool GetCharAtBackward(FX_FILESIZE pos, uint8_t& ch); 68 bool GetCharAtBackward(FX_FILESIZE pos, uint8_t& ch);
70 void GetNextWordInternal(bool* bIsNumber); 69 void GetNextWordInternal(bool* bIsNumber);
71 bool IsWholeWord(FX_FILESIZE startpos, 70 bool IsWholeWord(FX_FILESIZE startpos,
72 FX_FILESIZE limit, 71 FX_FILESIZE limit,
73 const CFX_ByteStringC& tag, 72 const CFX_ByteStringC& tag,
74 bool checkKeyword); 73 bool checkKeyword);
75 74
76 CFX_ByteString ReadString(); 75 CFX_ByteString ReadString();
77 CFX_ByteString ReadHexString(); 76 CFX_ByteString ReadHexString();
78 unsigned int ReadEOLMarkers(FX_FILESIZE pos); 77 unsigned int ReadEOLMarkers(FX_FILESIZE pos);
79 CPDF_Stream* ReadStream(CPDF_Dictionary* pDict, 78 std::unique_ptr<CPDF_Stream> ReadStream(CPDF_Dictionary* pDict,
80 uint32_t objnum, 79 uint32_t objnum,
81 uint32_t gennum); 80 uint32_t gennum);
82 81
83 CFX_ByteString MaybeIntern(const CFX_ByteString& str); 82 CFX_ByteString MaybeIntern(const CFX_ByteString& str);
84 inline bool CheckPosition(FX_FILESIZE pos) { 83 inline bool CheckPosition(FX_FILESIZE pos) {
85 return m_BufOffset >= pos || 84 return m_BufOffset >= pos ||
86 static_cast<FX_FILESIZE>(m_BufOffset + m_BufSize) <= pos; 85 static_cast<FX_FILESIZE>(m_BufOffset + m_BufSize) <= pos;
87 } 86 }
88 87
89 FX_FILESIZE m_Pos; 88 FX_FILESIZE m_Pos;
90 uint32_t m_MetadataObjnum; 89 uint32_t m_MetadataObjnum;
91 IFX_SeekableReadStream* m_pFileAccess; 90 IFX_SeekableReadStream* m_pFileAccess;
92 FX_FILESIZE m_HeaderOffset; 91 FX_FILESIZE m_HeaderOffset;
93 FX_FILESIZE m_FileLen; 92 FX_FILESIZE m_FileLen;
94 uint8_t* m_pFileBuf; 93 uint8_t* m_pFileBuf;
95 uint32_t m_BufSize; 94 uint32_t m_BufSize;
96 FX_FILESIZE m_BufOffset; 95 FX_FILESIZE m_BufOffset;
97 std::unique_ptr<CPDF_CryptoHandler> m_pCryptoHandler; 96 std::unique_ptr<CPDF_CryptoHandler> m_pCryptoHandler;
98 uint8_t m_WordBuffer[257]; 97 uint8_t m_WordBuffer[257];
99 uint32_t m_WordSize; 98 uint32_t m_WordSize;
100 CFX_WeakPtr<CFX_ByteStringPool> m_pPool; 99 CFX_WeakPtr<CFX_ByteStringPool> m_pPool;
101 }; 100 };
102 101
103 #endif // CORE_FPDFAPI_PARSER_CPDF_SYNTAX_PARSER_H_ 102 #endif // CORE_FPDFAPI_PARSER_CPDF_SYNTAX_PARSER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698