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 <cstddef> | 5 #include <cstddef> |
6 #include <cstdint> | 6 #include <cstdint> |
7 #include <limits> | |
8 #include <memory> | 7 #include <memory> |
9 | 8 |
10 #include "core/fxcrt/fx_basic.h" | 9 #include "core/fxcrt/fx_basic.h" |
| 10 #include "core/fxcrt/fx_safe_types.h" |
11 #include "core/fxcrt/fx_system.h" | 11 #include "core/fxcrt/fx_system.h" |
| 12 #include "third_party/base/ptr_util.h" |
12 #include "xfa/fde/xml/fde_xml_imp.h" | 13 #include "xfa/fde/xml/fde_xml_imp.h" |
13 #include "xfa/fxfa/parser/cxfa_xml_parser.h" | 14 #include "xfa/fxfa/parser/cxfa_xml_parser.h" |
14 #include "xfa/fxfa/parser/cxfa_widetextread.h" | 15 #include "xfa/fxfa/parser/cxfa_widetextread.h" |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 CFDE_XMLNode* XFA_FDEExtension_GetDocumentNode( | 19 CFDE_XMLNode* XFA_FDEExtension_GetDocumentNode( |
19 CFDE_XMLDoc* pXMLDoc, | 20 CFDE_XMLDoc* pXMLDoc, |
20 bool bVerifyWellFormness = false) { | 21 bool bVerifyWellFormness = false) { |
21 if (!pXMLDoc) { | 22 if (!pXMLDoc) { |
(...skipping 16 matching lines...) Expand all Loading... |
38 } | 39 } |
39 return pXMLNode; | 40 return pXMLNode; |
40 } | 41 } |
41 } | 42 } |
42 return nullptr; | 43 return nullptr; |
43 } | 44 } |
44 | 45 |
45 } // namespace | 46 } // namespace |
46 | 47 |
47 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | 48 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
48 if (size > std::numeric_limits<FX_STRSIZE>::max()) | 49 FX_SAFE_STRSIZE safe_size = size; |
| 50 if (!safe_size.IsValid()) |
49 return 0; | 51 return 0; |
50 | 52 |
51 CFX_WideString input = CFX_WideString::FromUTF8( | 53 CFX_WideString input = |
52 CFX_ByteStringC(data, static_cast<FX_STRSIZE>(size))); | 54 CFX_WideString::FromUTF8(CFX_ByteStringC(data, safe_size.ValueOrDie())); |
53 std::unique_ptr<IFX_Stream, ReleaseDeleter<IFX_Stream>> stream( | 55 std::unique_ptr<IFX_Stream, ReleaseDeleter<IFX_Stream>> stream( |
54 new CXFA_WideTextRead(input)); | 56 new CXFA_WideTextRead(input)); |
55 if (!stream) | 57 if (!stream) |
56 return 0; | 58 return 0; |
57 | 59 |
58 std::unique_ptr<CFDE_XMLDoc> doc(new CFDE_XMLDoc); | 60 std::unique_ptr<CFDE_XMLDoc> doc = pdfium::MakeUnique<CFDE_XMLDoc>(); |
59 std::unique_ptr<CFDE_XMLParser, ReleaseDeleter<CFDE_XMLParser>> parser( | 61 std::unique_ptr<CFDE_XMLParser, ReleaseDeleter<CFDE_XMLParser>> parser( |
60 new CXFA_XMLParser(doc->GetRoot(), stream.get())); | 62 new CXFA_XMLParser(doc->GetRoot(), stream.get())); |
61 | 63 |
62 if (!doc->LoadXML(parser.release())) | 64 if (!doc->LoadXML(parser.release())) |
63 return 0; | 65 return 0; |
64 | 66 |
65 int32_t load_result = doc->DoLoad(nullptr); | 67 int32_t load_result = doc->DoLoad(nullptr); |
66 if (load_result < 100) | 68 if (load_result < 100) |
67 return 0; | 69 return 0; |
68 | 70 |
69 (void)XFA_FDEExtension_GetDocumentNode(doc.get()); | 71 (void)XFA_FDEExtension_GetDocumentNode(doc.get()); |
70 return 0; | 72 return 0; |
71 } | 73 } |
OLD | NEW |