OLD | NEW |
---|---|
1 // Copyright 2016 The PDFium Authors. All rights reserved. | 1 // Copyright 2016 The 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 #ifndef TESTING_LIBFUZZER_XFA_CODEC_FUZZER_H_ | 5 #ifndef TESTING_LIBFUZZER_XFA_CODEC_FUZZER_H_ |
6 #define TESTING_LIBFUZZER_XFA_CODEC_FUZZER_H_ | 6 #define TESTING_LIBFUZZER_XFA_CODEC_FUZZER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "core/fxcodec/codec/include/ccodec_progressivedecoder.h" | 10 #include "core/fxcodec/codec/include/ccodec_progressivedecoder.h" |
(...skipping 25 matching lines...) Expand all Loading... | |
36 bitmap->GetHeight()); | 36 bitmap->GetHeight()); |
37 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) | 37 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) |
38 status = decoder->ContinueDecode(); | 38 status = decoder->ContinueDecode(); |
39 | 39 |
40 return 0; | 40 return 0; |
41 } | 41 } |
42 | 42 |
43 private: | 43 private: |
44 class Reader : public IFX_FileRead { | 44 class Reader : public IFX_FileRead { |
45 public: | 45 public: |
46 Reader(const uint8_t* data, size_t size) : m_data(data), m_size(size) {} | 46 Reader(const uint8_t* data, size_t size) |
47 : m_data(data), m_size(size), m_nCurPos(0) {} | |
47 ~Reader() {} | 48 ~Reader() {} |
48 | 49 |
49 void Release() override {} | 50 void Release() override {} |
50 | 51 |
51 FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override { | 52 FX_BOOL IsEOF() override { |
53 return m_nCurPos >= static_cast<FX_FILESIZE>(m_size); | |
54 } | |
55 | |
56 size_t ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override { | |
57 if (offset > m_size) | |
58 return 0; | |
52 if (offset + size > m_size) | 59 if (offset + size > m_size) |
53 size = m_size - offset; | 60 size = m_size - offset; |
54 memcpy(buffer, m_data + offset, size); | 61 memcpy(buffer, m_data + offset, size); |
55 return TRUE; | 62 m_nCurPos = offset + static_cast<FX_FILESIZE>(size); |
63 return size; | |
56 } | 64 } |
57 | 65 |
58 FX_FILESIZE GetSize() override { return static_cast<FX_FILESIZE>(m_size); } | 66 FX_FILESIZE GetSize() override { return static_cast<FX_FILESIZE>(m_size); } |
59 | 67 |
60 private: | 68 private: |
61 const uint8_t* const m_data; | 69 const uint8_t* const m_data; |
70 FX_FILESIZE m_nCurPos; | |
62 size_t m_size; | 71 size_t m_size; |
Tom Sepez
2016/10/19 23:12:48
this may be cleaner if it were FX_FILESIZE as well
| |
63 }; | 72 }; |
64 }; | 73 }; |
65 | 74 |
66 #endif // TESTING_LIBFUZZER_XFA_CODEC_FUZZER_H_ | 75 #endif // TESTING_LIBFUZZER_XFA_CODEC_FUZZER_H_ |
OLD | NEW |