File: xml.cc

package info (click to toggle)
sane-airscan 0.99.36-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,148 kB
  • sloc: ansic: 19,749; cpp: 156; makefile: 108
file content (42 lines) | stat: -rw-r--r-- 927 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Copyright 2020 The Chromium OS Authors. All rights reserved.
// See the sane-airscan top-level LICENSE for license terms and conditions.

#include <cstddef>
#include <cstdint>
#include <cstdio>

#include <libxml/xmlerror.h>

#include "airscan.h"

void noerrs(void *ctx, const char*msg, ...) {
  // Ignore the libxml error messages.
}

constexpr int kMaxInputSize = 32 * 1024;

extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
  // Limit fuzzer input size to 32KB.  libxml can take a very long time to
  // parse very large inputs, which causes the fuzzer to time out.
  if (size > kMaxInputSize) {
    return 0;
  }

  xmlSetGenericErrorFunc(NULL, noerrs);

  xml_rd *xml = NULL;
  if (xml_rd_begin(&xml, (const char*)data, size, NULL)) {
    return 0;
  }
  if (xml == NULL) {
    return 0;
  }

  while (!xml_rd_end(xml)) {
    xml_rd_deep_next(xml, 0);
  }

  xml_rd_finish(&xml);

  return 0;
}