OLD | NEW |
---|---|
(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 #include <cstdint> | |
6 | |
7 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream.h" | |
8 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h" | |
9 #include "core/fxcodec/codec/ccodec_jbig2module.h" | |
10 #include "core/fxcodec/include/JBig2_DocumentContext.h" | |
11 #include "core/fxcodec/jbig2/JBig2_Context.h" | |
12 #include "core/fxge/include/fx_dib.h" | |
13 | |
14 static uint32_t GetInteger(const uint8_t* data) { | |
15 return data[0] | data[1] << 8 | data[2] << 16 | data[3] << 24; | |
16 } | |
17 | |
18 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | |
19 const size_t kParameterSize = 8; | |
20 if (size < kParameterSize) | |
21 return 0; | |
Lei Zhang
2016/09/27 16:39:54
nit: blank line after, just like line 29-30.
kcwu
2016/09/27 17:03:08
Done.
| |
22 uint32_t width = GetInteger(data); | |
23 uint32_t height = GetInteger(data + 4); | |
24 size -= kParameterSize; | |
25 data += kParameterSize; | |
26 | |
27 std::unique_ptr<CFX_DIBitmap> bitmap(new CFX_DIBitmap); | |
28 if (!bitmap->Create(width, height, FXDIB_1bppRgb)) | |
29 return 0; | |
30 | |
31 std::unique_ptr<CPDF_Object> stream(new CPDF_Stream); | |
Lei Zhang
2016/09/27 16:39:54
CPDF_Object probably needs a ReleaseDeleter.
kcwu
2016/09/27 17:03:08
Ah, you are right.
I saw std::default_delete<CPDF_
| |
32 stream->AsStream()->SetData(data, size); | |
33 CCodec_Jbig2Context jbig2context; | |
Lei Zhang
2016/09/27 16:39:54
nit "jbig2_context" ?
Lei Zhang
2016/09/27 16:39:54
Declare this var and |document_context| below clos
kcwu
2016/09/27 17:03:08
Done.
kcwu
2016/09/27 17:03:08
Done.
| |
34 std::unique_ptr<JBig2_DocumentContext> document_context; | |
35 CPDF_StreamAcc src_stream; | |
36 src_stream.LoadAllData(stream->AsStream(), TRUE); | |
37 | |
38 CCodec_Jbig2Module module; | |
39 FXCODEC_STATUS status = module.StartDecode( | |
40 &jbig2context, &document_context, width, height, &src_stream, nullptr, | |
41 bitmap->GetBuffer(), bitmap->GetPitch(), nullptr); | |
42 | |
43 while (status == FXCODEC_STATUS_DECODE_TOBECONTINUE) | |
44 status = module.ContinueDecode(&jbig2context, nullptr); | |
45 return 0; | |
46 } | |
OLD | NEW |