Coverage Report

Created: 2026-04-12 06:44

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/inchi_input_fuzzer.c
Line
Count
Source
1
// Copyright 2020 Google Inc.
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
#include <stddef.h>
16
#include <stdint.h>
17
#include <stdlib.h>
18
#include <string.h>
19
20
#include "inchi_api.h"
21
22
// Define the maximum value for size_t. We return if the fuzzing input is equal
23
// to kSizeMax because appending the null-terminator to the InChI buffer would
24
// cause wraparound, thereby initializing the buffer to size 0.
25
static const size_t kSizeMax = (size_t)-1;
26
27
1.47k
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
28
29
1.47k
  if (size == kSizeMax)
30
0
    return 0;
31
32
1.47k
  char *szINCHISource = malloc(sizeof(char) * (size + 1));
33
1.47k
  memcpy(szINCHISource, data, size);
34
1.47k
  szINCHISource[size] = '\0'; // InChI string must be null-terminated
35
36
  // Buffer lengths taken from InChI API reference, located at
37
  // https://www.inchi-trust.org/download/104/InChI_API_Reference.pdf, page 24
38
1.47k
  char szINCHIKey[28], szXtra1[65], szXtra2[65];
39
1.47k
  GetINCHIKeyFromINCHI(szINCHISource, 0, 0, szINCHIKey, szXtra1, szXtra2);
40
41
1.47k
  inchi_InputINCHI inpInChI;
42
1.47k
  inpInChI.szInChI = szINCHISource;
43
1.47k
  inpInChI.szOptions = NULL;
44
45
1.47k
  inchi_Output out;
46
1.47k
  GetINCHIfromINCHI(&inpInChI, &out);
47
48
1.47k
  inchi_OutputStruct outStruct;
49
1.47k
  GetStructFromINCHI(&inpInChI, &outStruct);
50
51
1.47k
  free(szINCHISource);
52
1.47k
  FreeINCHI(&out);
53
1.47k
  FreeStructFromINCHI(&outStruct);
54
55
1.47k
  return 0;
56
1.47k
}