1 // Copyright 2017 PDFium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CORE_FPDFAPI_PARSER_CPDF_CROSS_REF_AVAIL_H_ 6 #define CORE_FPDFAPI_PARSER_CPDF_CROSS_REF_AVAIL_H_ 7 8 #include <queue> 9 #include <set> 10 11 #include "core/fpdfapi/parser/cpdf_data_avail.h" 12 #include "core/fxcrt/unowned_ptr.h" 13 14 class CPDF_SyntaxParser; 15 16 class CPDF_CrossRefAvail { 17 public: 18 CPDF_CrossRefAvail(CPDF_SyntaxParser* parser, 19 FX_FILESIZE last_crossref_offset); 20 ~CPDF_CrossRefAvail(); 21 last_crossref_offset()22 FX_FILESIZE last_crossref_offset() const { return last_crossref_offset_; } 23 24 CPDF_DataAvail::DocAvailStatus CheckAvail(); 25 26 private: 27 enum class State { 28 kCrossRefCheck, 29 kCrossRefV4ItemCheck, 30 kCrossRefV4TrailerCheck, 31 kDone, 32 }; 33 34 bool CheckReadProblems(); 35 bool CheckCrossRef(); 36 bool CheckCrossRefV4(); 37 bool CheckCrossRefV4Item(); 38 bool CheckCrossRefV4Trailer(); 39 bool CheckCrossRefStream(); 40 41 void AddCrossRefForCheck(FX_FILESIZE crossref_offset); 42 43 RetainPtr<CPDF_ReadValidator> GetValidator(); 44 45 UnownedPtr<CPDF_SyntaxParser> parser_; 46 const FX_FILESIZE last_crossref_offset_ = 0; 47 CPDF_DataAvail::DocAvailStatus current_status_ = 48 CPDF_DataAvail::DataNotAvailable; 49 State current_state_ = State::kCrossRefCheck; 50 FX_FILESIZE current_offset_ = 0; 51 std::queue<FX_FILESIZE> cross_refs_for_check_; 52 std::set<FX_FILESIZE> registered_crossrefs_; 53 }; 54 55 #endif // CORE_FPDFAPI_PARSER_CPDF_CROSS_REF_AVAIL_H_ 56