@@ -323,6 +323,11 @@ static int tdfb_init_coef(struct processing_module *mod, int source_nch,
323323 int i ;
324324
325325 /* Sanity checks */
326+ if (config -> size != cd -> config_size ) {
327+ comp_err (dev , "Incorrect configuration blob size" );
328+ return - EINVAL ;
329+ }
330+
326331 if (config -> num_output_channels > PLATFORM_MAX_CHANNELS ||
327332 !config -> num_output_channels ) {
328333 comp_err (dev , "invalid num_output_channels %d" ,
@@ -342,12 +347,21 @@ static int tdfb_init_coef(struct processing_module *mod, int source_nch,
342347 return - EINVAL ;
343348 }
344349
345- if (config -> num_angles > SOF_TDFB_MAX_ANGLES ) {
350+ /* In SOF v1.6 - 1.8 based beamformer topologies the multiple angles, mic locations,
351+ * and beam on/off switch were not defined. A most basic supported blob has num_angles
352+ * equal to 1. Mic locations data is optional.
353+ */
354+ if (config -> num_angles == 0 || config -> num_angles > SOF_TDFB_MAX_ANGLES ) {
346355 comp_err (dev , "invalid num_angles %d" ,
347356 config -> num_angles );
348357 return - EINVAL ;
349358 }
350359
360+ if (!config -> angle_enum_mult ) {
361+ comp_err (dev , "invalid angle_enum_mult" );
362+ return - EINVAL ;
363+ }
364+
351365 if (config -> beam_off_defined > 1 ) {
352366 comp_err (dev , "invalid beam_off_defined %d" ,
353367 config -> beam_off_defined );
@@ -360,15 +374,6 @@ static int tdfb_init_coef(struct processing_module *mod, int source_nch,
360374 return - EINVAL ;
361375 }
362376
363- /* In SOF v1.6 - 1.8 based beamformer topologies the multiple angles, mic locations,
364- * and beam on/off switch were not defined. Return error if such configuration is seen.
365- * A most basic blob has num_angles equals 1. Mic locations data is optional.
366- */
367- if (config -> num_angles == 0 && config -> num_mic_locations == 0 ) {
368- comp_err (dev , "ABI version less than 3.19.1 is not supported." );
369- return - EINVAL ;
370- }
371-
372377 /* Skip filter coefficients */
373378 num_filters = config -> num_filters * (config -> num_angles + config -> beam_off_defined );
374379 coefp = tdfb_filter_seek (config , num_filters );
@@ -423,6 +428,12 @@ static int tdfb_init_coef(struct processing_module *mod, int source_nch,
423428 cd -> filter_angles [min_delta_idx ].azimuth , idx );
424429 }
425430
431+ if (idx < 0 || idx + (int )config -> num_filters > num_filters ) {
432+ comp_err (dev , "invalid filter_index %d for angle %d" ,
433+ idx , cd -> filter_angles [min_delta_idx ].azimuth );
434+ return - EINVAL ;
435+ }
436+
426437 /* Seek to proper filter for requested angle or beam off configuration */
427438 coefp = tdfb_filter_seek (config , idx );
428439
@@ -451,6 +462,11 @@ static int tdfb_init_coef(struct processing_module *mod, int source_nch,
451462 for (i = 0 ; i < config -> num_filters ; i ++ ) {
452463 if (cd -> input_channel_select [i ] > max_ch )
453464 max_ch = cd -> input_channel_select [i ];
465+
466+ if (cd -> input_channel_select [i ] < 0 ) {
467+ comp_err (dev , "invalid channel select for filter %d" , i );
468+ return - EINVAL ;
469+ }
454470 }
455471
456472 /* The stream must contain at least the number of channels that is
@@ -641,7 +657,12 @@ static int tdfb_process(struct processing_module *mod,
641657
642658 /* Check for changed configuration */
643659 if (comp_is_new_data_blob_available (cd -> model_handler )) {
644- cd -> config = comp_get_data_blob (cd -> model_handler , NULL , NULL );
660+ cd -> config = comp_get_data_blob (cd -> model_handler , & cd -> config_size , NULL );
661+ if (!cd -> config || cd -> config_size < sizeof (* cd -> config ) ||
662+ cd -> config_size > SOF_TDFB_MAX_SIZE ) {
663+ comp_err (dev , "invalid configuration blob, size %zu" , cd -> config_size );
664+ return - EINVAL ;
665+ }
645666 ret = tdfb_setup (mod , audio_stream_get_channels (source ),
646667 audio_stream_get_channels (sink ),
647668 audio_stream_get_frm_fmt (source ));
@@ -705,7 +726,6 @@ static int tdfb_prepare(struct processing_module *mod,
705726 struct comp_buffer * sourceb , * sinkb ;
706727 struct comp_dev * dev = mod -> dev ;
707728 enum sof_ipc_frame frame_fmt ;
708- size_t data_size ;
709729 int source_channels ;
710730 int sink_channels ;
711731 int rate ;
@@ -735,9 +755,10 @@ static int tdfb_prepare(struct processing_module *mod,
735755 rate = audio_stream_get_rate (& sourceb -> stream );
736756
737757 /* Initialize filter */
738- cd -> config = comp_get_data_blob (cd -> model_handler , & data_size , NULL );
739- if (!cd -> config || !data_size ) {
740- comp_err (dev , "Missing a configuration blob." );
758+ cd -> config = comp_get_data_blob (cd -> model_handler , & cd -> config_size , NULL );
759+ if (!cd -> config || cd -> config_size < sizeof (* cd -> config ) ||
760+ cd -> config_size > SOF_TDFB_MAX_SIZE ) {
761+ comp_err (dev , "invalid configuration blob, size %zu" , cd -> config_size );
741762 ret = - EINVAL ;
742763 goto out ;
743764 }
0 commit comments