Oliver Chang | bf067b4 | 2016-03-18 16:45:33 -0700 | [diff] [blame] | 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 | #include <cstdint> |
| 6 | #include <memory> |
| 7 | #include <vector> |
| 8 | |
| 9 | #include "core/fxcodec/codec/codec_int.h" |
npm | 43c8a6a | 2016-09-30 08:37:51 -0700 | [diff] [blame^] | 10 | #include "core/fxge/fx_dib.h" |
Oliver Chang | bf067b4 | 2016-03-18 16:45:33 -0700 | [diff] [blame] | 11 | |
| 12 | CCodec_JpxModule g_module; |
| 13 | |
| 14 | struct DecoderDeleter { |
| 15 | void operator()(CJPX_Decoder* decoder) { g_module.DestroyDecoder(decoder); } |
| 16 | }; |
| 17 | |
| 18 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
| 19 | std::unique_ptr<CJPX_Decoder, DecoderDeleter> decoder( |
| 20 | g_module.CreateDecoder(data, size, nullptr)); |
| 21 | if (!decoder) |
| 22 | return 0; |
| 23 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 24 | uint32_t width; |
| 25 | uint32_t height; |
| 26 | uint32_t components; |
Oliver Chang | bf067b4 | 2016-03-18 16:45:33 -0700 | [diff] [blame] | 27 | g_module.GetImageInfo(decoder.get(), &width, &height, &components); |
| 28 | |
| 29 | FXDIB_Format format; |
| 30 | if (components == 1) { |
| 31 | format = FXDIB_8bppRgb; |
| 32 | } else if (components <= 3) { |
| 33 | format = FXDIB_Rgb; |
| 34 | } else if (components == 4) { |
| 35 | format = FXDIB_Rgb32; |
| 36 | } else { |
| 37 | width = (width * components + 2) / 3; |
| 38 | format = FXDIB_Rgb; |
| 39 | } |
| 40 | |
| 41 | std::unique_ptr<CFX_DIBitmap> bitmap(new CFX_DIBitmap); |
| 42 | if (!bitmap->Create(width, height, format)) |
| 43 | return 0; |
| 44 | |
| 45 | std::vector<uint8_t> output_offsets(components); |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 46 | for (uint32_t i = 0; i < components; ++i) |
Oliver Chang | bf067b4 | 2016-03-18 16:45:33 -0700 | [diff] [blame] | 47 | output_offsets[i] = i; |
| 48 | |
| 49 | g_module.Decode(decoder.get(), bitmap->GetBuffer(), bitmap->GetPitch(), |
| 50 | output_offsets); |
| 51 | return 0; |
| 52 | } |