xref: /aosp_15_r20/external/pdfium/testing/fuzzers/pdf_formcalc_translate_fuzzer.cc (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1 // Copyright 2016 The PDFium Authors
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 <stddef.h>
6 #include <stdint.h>
7 
8 #include "core/fxcrt/fx_safe_types.h"
9 #include "core/fxcrt/fx_string.h"
10 #include "fxjs/xfa/cfxjse_formcalc_context.h"
11 #include "testing/fuzzers/pdfium_fuzzer_util.h"
12 #include "testing/fuzzers/xfa_process_state.h"
13 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)14 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
15   auto* state = static_cast<XFAProcessState*>(FPDF_GetFuzzerPerProcessState());
16   WideString input = WideString::FromUTF8(ByteStringView(data, size));
17   CFXJSE_FormCalcContext::Translate(state->GetHeap(), input.AsStringView());
18   state->ForceGCAndPump();
19   return 0;
20 }
21