• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <string>
2 #include <sstream>
3 #include <cmath>
4 #include <algorithm>
5 #include "gif_fuzz_proto.pb.h"
6 
7 namespace gifProtoFuzzer
8 {
9 class ProtoConverter
10 {
11   public:
12 	std::string gifProtoToString(GifProto const &proto);
13 
14   private:
15 	template <class T>
16 	void visit(google::protobuf::RepeatedPtrField<T> const &_repeated_field);
17 	void visit(const GifProto &);
18 	void visit(const Header &);
19 	void visit(const LogicalScreenDescriptor &);
20 	void visit(const GlobalColorTable &);
21 	void visit(const ImageChunk &);
22 	void visit(const BasicChunk &);
23 	void visit(const ImageData &);
24 	void visit(const SubBlock &);
25 	void visit(const ImageDescriptor &);
26 	void visit(const LocalColorTable &);
27 	void visit(const GraphicControlExtension &);
28 	void visit(const PlainTextExtension &);
29 	void visit(const ApplicationExtension &);
30 	void visit(const CommentExtension &);
31 	void visit(const Trailer &);
32 
33 	// Utility functions
34 	void writeByte(uint8_t x);
35 	void writeWord(uint16_t x);
36 	void writeInt(uint32_t x);
37 	void writeLong(uint64_t x);
38 	static uint16_t extractWordFromUInt32(uint32_t a);
39 	static uint8_t extractByteFromUInt32(uint32_t a);
40 	static uint32_t tableExpToTableSize(uint32_t tableExp);
41 
42 	std::stringstream m_output;
43 	bool m_hasGCT = false;
44 	bool m_hasLCT = false;
45 	uint8_t m_globalColorExp = 0;
46 	uint8_t m_localColorExp = 0;
47 
48 	static constexpr unsigned char m_sig[] = {0x47, 0x49, 0x46};
49 	static constexpr unsigned char m_ver89a[] = {0x38, 0x39, 0x61};
50 	static constexpr unsigned char m_ver87a[] = {0x38, 0x37, 0x61};
51 };
52 } // namespace gifProtoFuzzer