1 /*
2 * Copyright 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 // Adapted from get_folder_items_packet_test
18
19 #include <fuzzer/FuzzedDataProvider.h>
20
21 #include "avrcp_test_packets.h"
22 #include "get_folder_items.h"
23 #include "packet_test_helper.h"
24
25 namespace bluetooth {
26 namespace avrcp {
27
28 using TestGetFolderItemsReqPacket = TestPacketType<GetFolderItemsRequest>;
29
LLVMFuzzerTestOneInput(uint8_t * data,size_t size)30 extern "C" int LLVMFuzzerTestOneInput(uint8_t* data, size_t size) {
31 auto builder = GetFolderItemsResponseBuilder::MakeNowPlayingBuilder(
32 Status::NO_ERROR, 0x0000, 0xFFFF);
33 std::set<AttributeEntry> attributes;
34 FuzzedDataProvider data_provider(data, size);
35 std::string s = data_provider.ConsumeRemainingBytesAsString();
36 attributes.insert(AttributeEntry(Attribute::TITLE, s));
37 auto song = MediaElementItem(0x02, s, attributes);
38 builder->AddSong(song);
39
40 auto test_packet = TestGetFolderItemsReqPacket::Make();
41 builder->Serialize(test_packet);
42 test_packet->GetData();
43
44 // Second test with the same data.
45 auto builder2 = GetFolderItemsResponseBuilder::MakeVFSBuilder(
46 Status::NO_ERROR, 0x0000, 0xFFFF);
47 auto folder = FolderItem(0x0000000000000001, 0x00, true, s);
48 builder2->AddFolder(folder);
49
50 test_packet = TestGetFolderItemsReqPacket::Make();
51 builder2->Serialize(test_packet);
52 test_packet->GetData();
53
54 // Third test with the same data.
55 MediaPlayerItem player1(1, s, true);
56
57 // Browsing Header + Status field + UID Counter field + Number of Items
58 // field
59 auto packet_size = BrowsePacket::kMinSize() + 5;
60 packet_size += player1.size();
61
62 auto builder3 = GetFolderItemsResponseBuilder::MakePlayerListBuilder(
63 Status::NO_ERROR, 0x0000, packet_size);
64
65 builder3->AddMediaPlayer(player1);
66
67 return 0;
68 }
69
70 } // namespace avrcp
71 } // namespace bluetooth
72