blob: efc171671cc1b0a35bc0cf8559053224191b6c05 [file] [log] [blame]
Oliver Change67d2182016-02-16 11:42:07 -08001// 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>
Oliver Change67d2182016-02-16 11:42:07 -08007#include <memory>
8
Lei Zhang30029412018-08-13 19:56:29 +00009#include "core/fxcrt/cfx_readonlymemorystream.h"
thestig62114cf2016-11-08 12:59:30 -080010#include "core/fxcrt/fx_safe_types.h"
npm43c8a6a2016-09-30 08:37:51 -070011#include "core/fxcrt/fx_system.h"
Dan Sinclair70180642018-05-02 16:02:03 +000012#include "core/fxcrt/xml/cfx_xmldocument.h"
dan sinclair384e6fe2018-04-17 21:55:18 +000013#include "core/fxcrt/xml/cfx_xmlelement.h"
Dan Sinclair0d86ecb2017-04-19 09:19:57 -040014#include "core/fxcrt/xml/cfx_xmlparser.h"
thestig62114cf2016-11-08 12:59:30 -080015#include "third_party/base/ptr_util.h"
Lei Zhanged176992018-08-13 23:19:29 +000016#include "third_party/base/span.h"
Oliver Change67d2182016-02-16 11:42:07 -080017
Oliver Change67d2182016-02-16 11:42:07 -080018extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
Ryan Harrisonbacf75e2017-09-27 10:58:52 -040019 FX_SAFE_SIZE_T safe_size = size;
thestig62114cf2016-11-08 12:59:30 -080020 if (!safe_size.IsValid())
Oliver Change67d2182016-02-16 11:42:07 -080021 return 0;
22
Lei Zhanged176992018-08-13 23:19:29 +000023 auto stream = pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(
24 pdfium::make_span(data, size));
Dan Sinclair70180642018-05-02 16:02:03 +000025 CFX_XMLParser parser(stream);
26 std::unique_ptr<CFX_XMLDocument> doc = parser.Parse();
27 if (!doc || !doc->GetRoot())
Oliver Change67d2182016-02-16 11:42:07 -080028 return 0;
29
Dan Sinclair70180642018-05-02 16:02:03 +000030 for (CFX_XMLNode* pXMLNode = doc->GetRoot()->GetFirstChild(); pXMLNode;
dsinclairbb47f9a2018-04-23 18:35:17 +000031 pXMLNode = pXMLNode->GetNextSibling()) {
Dan Sinclairfa3765c2018-02-13 21:44:33 +000032 if (pXMLNode->GetType() == FX_XMLNODE_Element)
33 break;
34 }
Oliver Change67d2182016-02-16 11:42:07 -080035 return 0;
36}