| 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> | 7 #include <limits> |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "core/fxcrt/include/fx_basic.h" | 10 #include "core/fxcrt/include/fx_basic.h" |
| 11 #include "core/fxcrt/include/fx_system.h" | 11 #include "core/fxcrt/include/fx_system.h" |
| 12 #include "xfa/fxfa/parser/xfa_parser.h" | 12 #include "xfa/fxfa/parser/xfa_parser.h" |
| 13 #include "xfa/fxfa/parser/xfa_parser_imp.h" | 13 #include "xfa/fxfa/parser/xfa_parser_imp.h" |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 IFDE_XMLNode* XFA_FDEExtension_GetDocumentNode( | 17 CFDE_XMLNode* XFA_FDEExtension_GetDocumentNode( |
| 18 IFDE_XMLDoc* pXMLDoc, | 18 CFDE_XMLDoc* pXMLDoc, |
| 19 FX_BOOL bVerifyWellFormness = FALSE) { | 19 FX_BOOL bVerifyWellFormness = FALSE) { |
| 20 if (!pXMLDoc) { | 20 if (!pXMLDoc) { |
| 21 return nullptr; | 21 return nullptr; |
| 22 } | 22 } |
| 23 IFDE_XMLNode* pXMLFakeRoot = pXMLDoc->GetRoot(); | 23 CFDE_XMLNode* pXMLFakeRoot = pXMLDoc->GetRoot(); |
| 24 for (IFDE_XMLNode* pXMLNode = | 24 for (CFDE_XMLNode* pXMLNode = |
| 25 pXMLFakeRoot->GetNodeItem(IFDE_XMLNode::FirstChild); | 25 pXMLFakeRoot->GetNodeItem(CFDE_XMLNode::FirstChild); |
| 26 pXMLNode; pXMLNode = pXMLNode->GetNodeItem(IFDE_XMLNode::NextSibling)) { | 26 pXMLNode; pXMLNode = pXMLNode->GetNodeItem(CFDE_XMLNode::NextSibling)) { |
| 27 if (pXMLNode->GetType() == FDE_XMLNODE_Element) { | 27 if (pXMLNode->GetType() == FDE_XMLNODE_Element) { |
| 28 if (bVerifyWellFormness) { | 28 if (bVerifyWellFormness) { |
| 29 for (IFDE_XMLNode* pNextNode = | 29 for (CFDE_XMLNode* pNextNode = |
| 30 pXMLNode->GetNodeItem(IFDE_XMLNode::NextSibling); | 30 pXMLNode->GetNodeItem(CFDE_XMLNode::NextSibling); |
| 31 pNextNode; | 31 pNextNode; |
| 32 pNextNode = pNextNode->GetNodeItem(IFDE_XMLNode::NextSibling)) { | 32 pNextNode = pNextNode->GetNodeItem(CFDE_XMLNode::NextSibling)) { |
| 33 if (pNextNode->GetType() == FDE_XMLNODE_Element) { | 33 if (pNextNode->GetType() == FDE_XMLNODE_Element) { |
| 34 return FALSE; | 34 return FALSE; |
| 35 } | 35 } |
| 36 } | 36 } |
| 37 } | 37 } |
| 38 return pXMLNode; | 38 return pXMLNode; |
| 39 } | 39 } |
| 40 } | 40 } |
| 41 return nullptr; | 41 return nullptr; |
| 42 } | 42 } |
| 43 | 43 |
| 44 } // namespace | 44 } // namespace |
| 45 | 45 |
| 46 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { | 46 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { |
| 47 if (size > std::numeric_limits<FX_STRSIZE>::max()) | 47 if (size > std::numeric_limits<FX_STRSIZE>::max()) |
| 48 return 0; | 48 return 0; |
| 49 | 49 |
| 50 CFX_WideString input = CFX_WideString::FromUTF8( | 50 CFX_WideString input = CFX_WideString::FromUTF8( |
| 51 reinterpret_cast<const char*>(data), static_cast<FX_STRSIZE>(size)); | 51 reinterpret_cast<const char*>(data), static_cast<FX_STRSIZE>(size)); |
| 52 std::unique_ptr<IFX_Stream, ReleaseDeleter<IFX_Stream>> stream( | 52 std::unique_ptr<IFX_Stream, ReleaseDeleter<IFX_Stream>> stream( |
| 53 XFA_CreateWideTextRead(input)); | 53 XFA_CreateWideTextRead(input)); |
| 54 if (!stream) | 54 if (!stream) |
| 55 return 0; | 55 return 0; |
| 56 | 56 |
| 57 std::unique_ptr<IFDE_XMLDoc> doc(IFDE_XMLDoc::Create()); | 57 std::unique_ptr<CFDE_XMLDoc> doc(new CFDE_XMLDoc); |
| 58 if (!doc) | 58 std::unique_ptr<CFDE_XMLParser, ReleaseDeleter<CFDE_XMLParser>> parser( |
| 59 return 0; | |
| 60 | |
| 61 std::unique_ptr<IFDE_XMLParser, ReleaseDeleter<IFDE_XMLParser>> parser( | |
| 62 new CXFA_XMLParser(doc->GetRoot(), stream.get())); | 59 new CXFA_XMLParser(doc->GetRoot(), stream.get())); |
| 63 if (!parser) | |
| 64 return 0; | |
| 65 | 60 |
| 66 if (!doc->LoadXML(parser.release())) | 61 if (!doc->LoadXML(parser.release())) |
| 67 return 0; | 62 return 0; |
| 68 | 63 |
| 69 int32_t load_result = doc->DoLoad(nullptr); | 64 int32_t load_result = doc->DoLoad(nullptr); |
| 70 if (load_result < 100) | 65 if (load_result < 100) |
| 71 return 0; | 66 return 0; |
| 72 | 67 |
| 73 (void)XFA_FDEExtension_GetDocumentNode(doc.get()); | 68 (void)XFA_FDEExtension_GetDocumentNode(doc.get()); |
| 74 return 0; | 69 return 0; |
| 75 } | 70 } |
| OLD | NEW |