/src/llama.cpp/fuzzers/fuzz_apply_template.cpp
Line | Count | Source |
1 | | /* Copyright 2024 Google LLC |
2 | | Licensed under the Apache License, Version 2.0 (the "License"); |
3 | | you may not use this file except in compliance with the License. |
4 | | You may obtain a copy of the License at |
5 | | http://www.apache.org/licenses/LICENSE-2.0 |
6 | | Unless required by applicable law or agreed to in writing, software |
7 | | distributed under the License is distributed on an "AS IS" BASIS, |
8 | | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
9 | | See the License for the specific language governing permissions and |
10 | | limitations under the License. |
11 | | */ |
12 | | |
13 | | #include "llama.h" |
14 | | #include <fuzzer/FuzzedDataProvider.h> |
15 | | |
16 | | char buf[4096]; |
17 | | |
18 | 1.64k | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
19 | 1.64k | FuzzedDataProvider fuzzed_data(data, size); |
20 | | |
21 | 1.64k | std::string p1 = fuzzed_data.ConsumeRandomLengthString(); |
22 | 1.64k | std::string p2 = fuzzed_data.ConsumeRandomLengthString(); |
23 | 1.64k | std::string p3 = fuzzed_data.ConsumeRandomLengthString(); |
24 | 1.64k | std::string p4 = fuzzed_data.ConsumeRandomLengthString(); |
25 | 1.64k | std::string p5 = fuzzed_data.ConsumeRandomLengthString(); |
26 | 1.64k | std::string p6 = fuzzed_data.ConsumeRandomLengthString(); |
27 | 1.64k | std::string p7 = fuzzed_data.ConsumeRandomLengthString(); |
28 | | |
29 | 1.64k | llama_chat_message conversation[] = { |
30 | 1.64k | {"system", p2.c_str()}, {"user", p3.c_str()}, |
31 | 1.64k | {"assistant", p4.c_str()}, {"user", p5.c_str()}, |
32 | 1.64k | {"assistant", p6.c_str()}, {"user", p7.c_str()}, |
33 | 1.64k | }; |
34 | 1.64k | size_t message_count = 6; |
35 | | |
36 | 1.64k | llama_chat_apply_template(p1.c_str(), conversation, message_count, |
37 | 1.64k | true, buf, 4096); |
38 | 1.64k | return 0; |
39 | 1.64k | } |