• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <cstddef>
6 #include <cstdint>
7 #include <memory>
8 
9 #include "core/fxcrt/cfx_readonlymemorystream.h"
10 #include "core/fxcrt/fx_safe_types.h"
11 #include "core/fxcrt/fx_system.h"
12 #include "core/fxcrt/xml/cfx_xmldocument.h"
13 #include "core/fxcrt/xml/cfx_xmlelement.h"
14 #include "core/fxcrt/xml/cfx_xmlparser.h"
15 #include "third_party/base/span.h"
16 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)17 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
18   FX_SAFE_SIZE_T safe_size = size;
19   if (!safe_size.IsValid())
20     return 0;
21 
22   auto stream = pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(
23       pdfium::make_span(data, size));
24   CFX_XMLParser parser(stream);
25   std::unique_ptr<CFX_XMLDocument> doc = parser.Parse();
26   if (!doc || !doc->GetRoot())
27     return 0;
28 
29   for (CFX_XMLNode* pXMLNode = doc->GetRoot()->GetFirstChild(); pXMLNode;
30        pXMLNode = pXMLNode->GetNextSibling()) {
31     if (pXMLNode->GetType() == CFX_XMLNode::Type::kElement)
32       break;
33   }
34   return 0;
35 }
36