Coverage Report

Created: 2026-08-31 06:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/molfile_fuzzer.c
Line
Count
Source
1
// Copyright 2026 Google LLC
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
// Molfile/SDfile text parser fuzzer.
16
//
17
// inchi_input_fuzzer feeds an InChI *string* (the InChI->structure direction),
18
// leaving the MOLfile/SDfile text reader (mol_fmt*.c / readinch.c) at 0%.
19
// MakeINCHIFromMolfileText parses a Molfile supplied as text and builds an
20
// InChI from it, exercising the V2000/V3000 connection-table reader directly.
21
22
#include <stddef.h>
23
#include <stdint.h>
24
#include <stdlib.h>
25
#include <string.h>
26
27
#include "inchi_api.h"
28
29
static const size_t kSizeMax = (size_t)-1;
30
31
5.07k
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
32
5.07k
  if (size == 0 || size == kSizeMax)
33
0
    return 0;
34
35
5.07k
  char *moltext = malloc(size + 1);
36
5.07k
  if (!moltext)
37
0
    return 0;
38
5.07k
  memcpy(moltext, data, size);
39
5.07k
  moltext[size] = '\0'; // Molfile text must be NUL-terminated
40
41
5.07k
  char options[] = ""; // non-const buffer (API takes char*)
42
43
5.07k
  inchi_Output out;
44
5.07k
  memset(&out, 0, sizeof(out));
45
5.07k
  MakeINCHIFromMolfileText(moltext, options, &out);
46
5.07k
  FreeINCHI(&out);
47
48
5.07k
  free(moltext);
49
5.07k
  return 0;
50
5.07k
}