1 /*
2  * Copyright (C) 2019 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 #include <cmath>
18 #include <cstdlib>
19 #include <cstring>
20 #include <ctime>
21 #include "FormatConvert.h"
22 
LLVMFuzzerTestOneInput(const uint8_t * data,std::size_t size)23 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, std::size_t size) {
24     if (size < 256) {
25         return 0;
26     }
27 
28     std::srand(std::time(nullptr));  // use current time as seed for random generator
29     int random_variable = std::rand() % 10;
30     int width = (int)sqrt(size);
31     int height = width * ((float)random_variable / 10.0);
32 
33     uint8_t* src = (uint8_t*)malloc(sizeof(uint8_t) * size);
34     memcpy(src, data, sizeof(uint8_t) * (size));
35     uint32_t* tgt = (uint32_t*)malloc(sizeof(uint32_t) * size);
36 
37 #ifdef COPY_NV21_TO_RGB32
38     android::hardware::automotive::evs::common::Utils::copyNV21toRGB32(width, height, src, tgt, 0);
39 #elif COPY_NV21_TO_BGR32
40     android::hardware::automotive::evs::common::Utils::copyNV21toBGR32(width, height, src, tgt, 0);
41 #elif COPY_YV12_TO_RGB32
42     android::hardware::automotive::evs::common::Utils::copyYV12toRGB32(width, height, src, tgt, 0);
43 #elif COPY_YV12_TO_BGR32
44     android::hardware::automotive::evs::common::Utils::copyYV12toBGR32(width, height, src, tgt, 0);
45 #elif COPY_YUYV_TO_RGB32
46     android::hardware::automotive::evs::common::Utils::copyYUYVtoRGB32(width, height, src, 0, tgt,
47                                                                        0);
48 #elif COPY_YUYV_TO_BGR32
49     android::hardware::automotive::evs::common::Utils::copyYUYVtoBGR32(width, height, src, 0, tgt,
50                                                                        0);
51 #endif
52 
53     free(src);
54     free(tgt);
55 
56     return 0;
57 }
58