| 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 #include <memory> | 5 #include "testing/libfuzzer/xfa_codec_fuzzer.h" |
| 6 | |
| 7 #include "core/fxcodec/codec/include/ccodec_progressivedecoder.h" | |
| 8 #include "core/fxcodec/include/fx_codec.h" | |
| 9 #include "core/fxcrt/include/fx_stream.h" | |
| 10 | |
| 11 namespace { | |
| 12 | |
| 13 class Reader : public IFX_FileRead { | |
| 14 public: | |
| 15 Reader(const uint8_t* data, size_t size) : m_data(data), m_size(size) {} | |
| 16 ~Reader() {} | |
| 17 | |
| 18 void Release() override {} | |
| 19 | |
| 20 FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override { | |
| 21 if (offset + size > m_size) | |
| 22 size = m_size - offset; | |
| 23 memcpy(buffer, m_data + offset, size); | |
| 24 return TRUE; | |
| 25 } | |
| 26 | |
| 27 FX_FILESIZE GetSize() override { return static_cast<FX_FILESIZE>(m_size); } | |
| 28 | |
| 29 private: | |
| 30 const uint8_t* const m_data; | |
| 31 size_t m_size; | |
| 32 }; | |
| 33 | |
| 34 } // namespace | |
| 35 | 6 |
| 36 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | 7 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
| 37 std::unique_ptr<CCodec_ModuleMgr> mgr(new CCodec_ModuleMgr()); | 8 return XFACodecFuzzer::Fuzz(data, size, FXCODEC_IMAGE_PNG); |
| 38 std::unique_ptr<CCodec_ProgressiveDecoder> decoder( | |
| 39 mgr->CreateProgressiveDecoder()); | |
| 40 Reader source(data, size); | |
| 41 | |
| 42 FXCODEC_STATUS status = | |
| 43 decoder->LoadImageInfo(&source, FXCODEC_IMAGE_PNG, nullptr); | |
| 44 if (status != FXCODEC_STATUS_FRAME_READY) | |
| 45 return 0; | |
| 46 | |
| 47 std::unique_ptr<CFX_DIBitmap> bitmap(new CFX_DIBitmap); | |
| 48 bitmap->Create(decoder->GetWidth(), decoder->GetHeight(), FXDIB_Argb); | |
| 49 | |
| 50 int32_t frames; | |
| 51 if (decoder->GetFrames(frames) != FXCODEC_STATUS_DECODE_READY || frames == 0) | |
| 52 return 0; | |
| 53 | |
| 54 status = decoder->StartDecode(bitmap.get(), 0, 0, bitmap->GetWidth(), | |
| 55 bitmap->GetHeight()); | |
| 56 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) | |
| 57 status = decoder->ContinueDecode(); | |
| 58 | |
| 59 return 0; | |
| 60 } | 9 } |
| OLD | NEW |