Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: testing/libfuzzer/xfa_codec_fuzzer.h

Issue 2045613002: Add GIF, BMP, JPEG and TIFF XFA fuzzers (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « testing/libfuzzer/pdf_codec_tiff_fuzzer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef TESTING_LIBFUZZER_XFA_CODEC_FUZZER_H_
6 #define TESTING_LIBFUZZER_XFA_CODEC_FUZZER_H_
7
8 #include <memory>
9
10 #include "core/fxcodec/codec/include/ccodec_progressivedecoder.h"
11 #include "core/fxcodec/include/fx_codec.h"
12 #include "core/fxcrt/include/fx_stream.h"
13
14 class XFACodecFuzzer {
15 public:
16 static int Fuzz(const uint8_t* data, size_t size, FXCODEC_IMAGE_TYPE type) {
17 std::unique_ptr<CCodec_ModuleMgr> mgr(new CCodec_ModuleMgr());
18 std::unique_ptr<CCodec_ProgressiveDecoder> decoder(
19 mgr->CreateProgressiveDecoder());
20 Reader source(data, size);
21
22 FXCODEC_STATUS status = decoder->LoadImageInfo(&source, type, nullptr);
23 if (status != FXCODEC_STATUS_FRAME_READY)
24 return 0;
25
26 std::unique_ptr<CFX_DIBitmap> bitmap(new CFX_DIBitmap);
27 bitmap->Create(decoder->GetWidth(), decoder->GetHeight(), FXDIB_Argb);
28
29 int32_t frames;
30 if (decoder->GetFrames(frames) != FXCODEC_STATUS_DECODE_READY ||
31 frames == 0)
32 return 0;
33
34 status = decoder->StartDecode(bitmap.get(), 0, 0, bitmap->GetWidth(),
35 bitmap->GetHeight());
36 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE)
37 status = decoder->ContinueDecode();
38
39 return 0;
40 }
41
42 private:
43 class Reader : public IFX_FileRead {
44 public:
45 Reader(const uint8_t* data, size_t size) : m_data(data), m_size(size) {}
46 ~Reader() {}
47
48 void Release() override {}
49
50 FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override {
51 if (offset + size > m_size)
52 size = m_size - offset;
53 memcpy(buffer, m_data + offset, size);
54 return TRUE;
55 }
56
57 FX_FILESIZE GetSize() override { return static_cast<FX_FILESIZE>(m_size); }
58
59 private:
60 const uint8_t* const m_data;
61 size_t m_size;
62 };
63 };
64
65 #endif // TESTING_LIBFUZZER_XFA_CODEC_FUZZER_H_
OLDNEW
« no previous file with comments | « testing/libfuzzer/pdf_codec_tiff_fuzzer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698