Coverage Report

Created: 2025-07-04 06:48

/src/sample_encode_fuzzer.cc
Line
Count
Source
1
// Copyright 2020 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
#include <fuzzer/FuzzedDataProvider.h>
16
17
#include <cstddef>
18
#include <cstdint>
19
#include <string>
20
#include <vector>
21
22
#include "sentencepiece_processor.h"
23
24
128
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
25
128
  sentencepiece::SentencePieceProcessor fuzz_sp_processor;
26
128
  FuzzedDataProvider data_provider(data, size);
27
128
  const int nbest_size = data_provider.ConsumeIntegral<int>();
28
128
  const float alpha = data_provider.ConsumeFloatingPoint<float>();
29
128
  const std::string in_string = data_provider.ConsumeRemainingBytesAsString();
30
31
128
  fuzz_sp_processor.SampleEncodeAsSerializedProto(in_string, nbest_size, alpha);
32
128
  return 0;
33
128
}