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/ccodec_progressivedecoder.h" | 10 #include "core/fxcodec/codec/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_SeekableReadStream { | 44 class Reader : public IFX_SeekableReadStream { |
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 bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override { | 52 bool IsEOF() override { return m_nCurPos >= m_size; } |
| 53 |
| 54 size_t ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override { |
52 if (offset < 0 || static_cast<size_t>(offset) >= m_size) | 55 if (offset < 0 || static_cast<size_t>(offset) >= m_size) |
53 return false; | 56 return 0; |
54 if (offset + size > m_size) | 57 if (offset + size > m_size) |
55 size = m_size - offset; | 58 size = m_size - offset; |
56 if (size == 0) | 59 if (size == 0) |
57 return false; | 60 return 0; |
58 | 61 |
59 memcpy(buffer, m_data + offset, size); | 62 memcpy(buffer, m_data + offset, size); |
60 return true; | 63 m_nCurPos = offset + static_cast<FX_FILESIZE>(size); |
| 64 return size; |
61 } | 65 } |
62 | 66 |
63 FX_FILESIZE GetSize() override { return static_cast<FX_FILESIZE>(m_size); } | 67 FX_FILESIZE GetSize() override { return m_size; } |
64 | 68 |
65 private: | 69 private: |
66 const uint8_t* const m_data; | 70 const uint8_t* const m_data; |
67 size_t m_size; | 71 FX_FILESIZE m_nCurPos; |
| 72 FX_FILESIZE m_size; |
68 }; | 73 }; |
69 }; | 74 }; |
70 | 75 |
71 #endif // TESTING_LIBFUZZER_XFA_CODEC_FUZZER_H_ | 76 #endif // TESTING_LIBFUZZER_XFA_CODEC_FUZZER_H_ |
OLD | NEW |