99
1010#include " qpl/qpl.h"
1111
12+ #include " filtering_fuzz_common.hpp"
13+
1214#ifndef QPL_EXECUTION_PATH
1315#define QPL_EXECUTION_PATH qpl_path_software
1416#endif
@@ -33,36 +35,50 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* Data, size_t Size) {
3335 Size--;
3436
3537 if (Size > sizeof (extract_properties)) {
36- auto * properties_ptr = reinterpret_cast <const extract_properties*>(Data);
37- std::vector<uint8_t > source (Data + sizeof (extract_properties), Data + Size);
38- std::vector<uint8_t > destination (properties_ptr->destination_size );
39-
40- qpl_status status;
41- uint32_t job_size = 0 ;
42-
43- // Job initialization
44- status = qpl_get_job_size (execution_path, &job_size);
45- if (status != QPL_STS_OK) { return 0 ; }
46-
47- auto job_buffer = std::make_unique<uint8_t []>(job_size);
48- qpl_job* job_ptr = reinterpret_cast <qpl_job*>(job_buffer.get ());
49-
50- status = qpl_init_job (execution_path, job_ptr);
51- if (status != QPL_STS_OK) { return 0 ; }
52-
53- job_ptr->next_in_ptr = source.data ();
54- job_ptr->available_in = source.size ();
55- job_ptr->next_out_ptr = destination.data ();
56- job_ptr->available_out = destination.size ();
57- job_ptr->op = qpl_op_extract;
58- job_ptr->num_input_elements = properties_ptr->number_of_elements ;
59- job_ptr->src1_bit_width = properties_ptr->input_bit_width ;
60- job_ptr->param_low = properties_ptr->low_index_boundary ;
61- job_ptr->param_high = properties_ptr->high_index_boundary ;
62- job_ptr->out_bit_width = properties_ptr->output_bit_width ;
63- job_ptr->parser = parser;
64-
65- status = qpl_execute_job (job_ptr);
38+ extract_properties properties = *reinterpret_cast <const extract_properties*>(Data);
39+
40+ // Make sure the output bit width is in the valid range of enum qpl_out_format
41+ properties.output_bit_width =
42+ static_cast <qpl_out_format>(static_cast <uint8_t >(properties.output_bit_width ) % 4 );
43+
44+ const int64_t source_size = static_cast <int64_t >(Size) - sizeof (extract_properties);
45+ const bool is_rle_parser = qpl_p_parquet_rle == parser;
46+ const auto source_ptr = Data + sizeof (extract_properties);
47+ bool is_good_data = validate_filtering_input (properties.input_bit_width , source_ptr, is_rle_parser,
48+ properties.output_bit_width , properties.number_of_elements ,
49+ source_size, properties.destination_size );
50+ if (properties.high_index_boundary > properties.number_of_elements ) { is_good_data = false ; }
51+ if (is_good_data) {
52+ std::vector<uint8_t > source (Data + sizeof (extract_properties), Data + Size);
53+ std::vector<uint8_t > destination (properties.destination_size );
54+
55+ qpl_status status;
56+ uint32_t job_size = 0 ;
57+
58+ // Job initialization
59+ status = qpl_get_job_size (execution_path, &job_size);
60+ if (status != QPL_STS_OK) { return 0 ; }
61+
62+ auto job_buffer = std::make_unique<uint8_t []>(job_size);
63+ qpl_job* job_ptr = reinterpret_cast <qpl_job*>(job_buffer.get ());
64+
65+ status = qpl_init_job (execution_path, job_ptr);
66+ if (status != QPL_STS_OK) { return 0 ; }
67+
68+ job_ptr->next_in_ptr = source.data ();
69+ job_ptr->available_in = source.size ();
70+ job_ptr->next_out_ptr = destination.data ();
71+ job_ptr->available_out = destination.size ();
72+ job_ptr->op = qpl_op_extract;
73+ job_ptr->num_input_elements = properties.number_of_elements ;
74+ job_ptr->src1_bit_width = properties.input_bit_width ;
75+ job_ptr->param_low = properties.low_index_boundary ;
76+ job_ptr->param_high = properties.high_index_boundary ;
77+ job_ptr->out_bit_width = properties.output_bit_width ;
78+ job_ptr->parser = parser;
79+
80+ status = qpl_execute_job (job_ptr);
81+ }
6682 }
6783
6884 return 0 ;
0 commit comments