From eaf94778068a3bc21badca00e3b820228c8efe9a Mon Sep 17 00:00:00 2001 From: vaclav Date: Tue, 14 Feb 2023 09:41:26 +0100 Subject: [PATCH] fix issue 343: safeguard for function to_upper(); under FIX_343_TO_UPPER --- apps/decoder.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++ apps/encoder.c | 31 +++++++++++++++++++- apps/renderer.c | 9 ++++++ lib_com/options.h | 3 ++ 4 files changed, 115 insertions(+), 1 deletion(-) diff --git a/apps/decoder.c b/apps/decoder.c index 76a053c0f6..3f0bb0924a 100644 --- a/apps/decoder.c +++ b/apps/decoder.c @@ -586,6 +586,9 @@ static IVAS_DEC_AUDIO_CONFIG cmdline2config( char argv_to_upper[FILENAME_MAX]; strncpy( argv_to_upper, argv, sizeof( argv_to_upper ) - 1 ); +#ifdef FIX_343_TO_UPPER + argv_to_upper[sizeof( argv_to_upper ) - 1] = '\0'; +#endif to_upper( argv_to_upper ); if ( strcmp( argv_to_upper, "EXT" ) == 0 ) /* external renderer */ @@ -664,7 +667,9 @@ static bool parseCmdlIVAS_dec( char argv_to_upper[FILENAME_MAX]; #ifdef DEBUGGING float ftmp; +#ifndef FIX_343_TO_UPPER char stmp[FILENAME_MAX]; +#endif arg->forcedRendMode = IVAS_DEC_FORCE_REND_UNFORCED; arg->forceSubframeBinauralization = false; @@ -728,6 +733,9 @@ static bool parseCmdlIVAS_dec( while ( argv[i][0] == '-' ) { strncpy( argv_to_upper, argv[i], sizeof( argv_to_upper ) - 1 ); +#ifdef FIX_343_TO_UPPER + argv_to_upper[sizeof( argv_to_upper ) - 1] = '\0'; +#endif to_upper( argv_to_upper ); if ( strcmp( argv_to_upper, "-VOIP" ) == 0 ) @@ -735,13 +743,21 @@ static bool parseCmdlIVAS_dec( arg->voipMode = 1; i++; } +#ifdef FIX_343_TO_UPPER + else if ( strcmp( argv_to_upper, "-VOIP_HF_ONLY=0" ) == 0 ) +#else else if ( strcmp( to_upper( argv[i] ), "-VOIP_HF_ONLY=0" ) == 0 ) +#endif { arg->voipMode = 1; arg->inputFormat = IVAS_DEC_INPUT_FORMAT_RTPDUMP; i++; } +#ifdef FIX_343_TO_UPPER + else if ( strcmp( argv_to_upper, "-VOIP_HF_ONLY=1" ) == 0 ) +#else else if ( strcmp( to_upper( argv[i] ), "-VOIP_HF_ONLY=1" ) == 0 ) +#endif { arg->voipMode = 1; arg->inputFormat = IVAS_DEC_INPUT_FORMAT_RTPDUMP_HF; @@ -814,8 +830,14 @@ static bool parseCmdlIVAS_dec( i++; if ( i < argc - 3 ) { +#ifdef FIX_343_TO_UPPER + strncpy( argv_to_upper, argv[i], sizeof( argv_to_upper ) - 1 ); + argv_to_upper[sizeof( argv_to_upper ) - 1] = '\0'; + arg->forcedRendMode = parseForcedRendModeDec( argv_to_upper ); +#else strncpy( stmp, argv[i], sizeof( stmp ) ); arg->forcedRendMode = parseForcedRendModeDec( stmp ); +#endif i++; } } @@ -867,8 +889,30 @@ static bool parseCmdlIVAS_dec( usage_dec(); return false; } + +#ifdef FIX_343_TO_UPPER + strncpy( argv_to_upper, argv[i + 1], sizeof( argv_to_upper ) - 1 ); + argv_to_upper[sizeof( argv_to_upper ) - 1] = '\0'; + to_upper( argv_to_upper ); + + if ( strcmp( argv_to_upper, "REF" ) == 0 ) + { + arg->orientation_tracking = IVAS_PUBLIC_ORIENT_TRK_REF; + } + else if ( strcmp( argv_to_upper, "AVG" ) == 0 ) + { + arg->orientation_tracking = IVAS_PUBLIC_ORIENT_TRK_AVG; + } + else + { + fprintf( stderr, "Error: Invalid orientation tracking type %s \n\n", argv[i + 1] ); + usage_dec(); + return false; + } +#else char tmp[4]; strcpy( tmp, argv[i + 1] ); + if ( strcmp( to_upper( tmp ), "REF" ) == 0 ) { arg->orientation_tracking = IVAS_PUBLIC_ORIENT_TRK_REF; @@ -883,6 +927,7 @@ static bool parseCmdlIVAS_dec( usage_dec(); return false; } +#endif i += 2; } else if ( strcmp( argv_to_upper, "-RENDER_CONFIG" ) == 0 ) @@ -909,6 +954,33 @@ static bool parseCmdlIVAS_dec( return false; } +#ifdef FIX_343_TO_UPPER + strncpy( argv_to_upper, argv[i], sizeof( argv_to_upper ) - 1 ); + argv_to_upper[sizeof( argv_to_upper ) - 1] = '\0'; + if ( ( strcmp( argv_to_upper, "CENTER" ) == 0 ) || ( strchr( argv_to_upper, 'C' ) != NULL ) ) + { + arg->no_diegetic_pan = 0.f; + } + else if ( ( strcmp( argv_to_upper, "LEFT" ) == 0 ) || ( strchr( argv_to_upper, 'L' ) != NULL ) ) + { + arg->no_diegetic_pan = -1.f; + } + else if ( ( strcmp( argv_to_upper, "RIGHT" ) == 0 ) || ( strchr( argv_to_upper, 'R' ) != NULL ) ) + { + arg->no_diegetic_pan = 1.f; + } + else + { + arg->no_diegetic_pan = (float) atof( argv_to_upper ); + + if ( arg->no_diegetic_pan > 1.0f || arg->no_diegetic_pan < -1.0f ) + { + fprintf( stderr, "Error: Incorrect value for panning option argument specified: %s\n\n", argv[i] ); + usage_dec(); + return false; + } + } +#else char *param = to_upper( argv[i] ); if ( ( strcmp( param, "CENTER" ) == 0 ) || ( strchr( param, 'C' ) != NULL ) ) { @@ -933,6 +1005,7 @@ static bool parseCmdlIVAS_dec( return false; } } +#endif i++; } diff --git a/apps/encoder.c b/apps/encoder.c index b73e3d27f9..2aab6d5ae8 100644 --- a/apps/encoder.c +++ b/apps/encoder.c @@ -884,7 +884,11 @@ static bool parseCmdlIVAS_enc( while ( i < argc - 4 ) { strncpy( argv_to_upper, argv[i], sizeof( argv_to_upper ) - 1 ); +#ifdef FIX_343_TO_UPPER + argv_to_upper[sizeof( argv_to_upper ) - 1] = '\0'; +#endif to_upper( argv_to_upper ); + /*-----------------------------------------------------------------* * Bandwidth limitation *-----------------------------------------------------------------*/ @@ -894,6 +898,9 @@ static bool parseCmdlIVAS_enc( arg->max_bwidth_user = true; strncpy( stmp, argv[i + 1], sizeof( stmp ) - 1 ); +#ifdef FIX_343_TO_UPPER + stmp[sizeof( stmp ) - 1] = '\0'; +#endif to_upper( stmp ); if ( strcmp( stmp, "-NB" ) == 0 || strcmp( stmp, "NB" ) == 0 ) @@ -1081,7 +1088,9 @@ static bool parseCmdlIVAS_enc( if ( i < argc - 4 ) { strncpy( stmp, argv[i], sizeof( stmp ) ); - +#ifdef FIX_343_TO_UPPER + stmp[sizeof( stmp ) - 1] = '\0'; +#endif to_upper( argv[i] ); if ( strcmp( argv[i], "LO" ) == 0 ) { @@ -1369,6 +1378,25 @@ static bool parseCmdlIVAS_enc( if ( i < argc - 4 ) { +#ifdef FIX_343_TO_UPPER + if ( strcmp( argv[i], "5_1" ) == 0 ) + { + arg->inputFormatConfig.mcLayout = IVAS_ENC_MC_5_1; + } + else if ( strcmp( argv[i], "7_1" ) == 0 ) + { + arg->inputFormatConfig.mcLayout = IVAS_ENC_MC_7_1; + } + else if ( strcmp( argv[i], "5_1_2" ) == 0 ) + { + arg->inputFormatConfig.mcLayout = IVAS_ENC_MC_5_1_2; + } + else if ( strcmp( argv[i], "5_1_4" ) == 0 ) + { + arg->inputFormatConfig.mcLayout = IVAS_ENC_MC_5_1_4; + } + else if ( strcmp( argv[i], "7_1_4" ) == 0 ) +#else if ( strcmp( to_upper( argv[i] ), "5_1" ) == 0 ) { arg->inputFormatConfig.mcLayout = IVAS_ENC_MC_5_1; @@ -1386,6 +1414,7 @@ static bool parseCmdlIVAS_enc( arg->inputFormatConfig.mcLayout = IVAS_ENC_MC_5_1_4; } else if ( strcmp( to_upper( argv[i] ), "7_1_4" ) == 0 ) +#endif { arg->inputFormatConfig.mcLayout = IVAS_ENC_MC_7_1_4; } diff --git a/apps/renderer.c b/apps/renderer.c index 19b88a92dd..47285b81a4 100644 --- a/apps/renderer.c +++ b/apps/renderer.c @@ -490,6 +490,9 @@ static void setupWithSingleFormatInput( /* It is allowed on CLI to have no metadata for an ISM input - skip opening if string is empty or contains "NULL" */ char charBuf[FILENAME_MAX]; strncpy( charBuf, args.inMetadataFilePaths[i], min( FILENAME_MAX, RENDERER_MAX_CLI_ARG_LENGTH ) - 1 ); +#ifdef FIX_343_TO_UPPER + charBuf[min( FILENAME_MAX, RENDERER_MAX_CLI_ARG_LENGTH ) - 1] = '\0'; +#endif to_upper( charBuf ); if ( isEmptyString( args.inMetadataFilePaths[i] ) || strncmp( charBuf, "NULL", 4 ) == 0 ) { @@ -1100,6 +1103,9 @@ static bool parseInConfig( /* First check if input is being set to scene description file - this is not covered by parseAudioConfig(). */ strncpy( charBuf, inFormatStr, sizeof( charBuf ) - 1 ); +#ifdef FIX_343_TO_UPPER + charBuf[sizeof( charBuf ) - 1] = '\0'; +#endif to_upper( charBuf ); if ( strcmp( charBuf, "META" ) == 0 ) { @@ -1285,6 +1291,9 @@ static IVAS_REND_AudioConfig parseAudioConfig( charBuf[13] = '\0'; strncpy( charBuf, configString, sizeof( charBuf ) - 1 ); +#ifdef FIX_343_TO_UPPER + charBuf[sizeof( charBuf ) - 1] = '\0'; +#endif to_upper( charBuf ); if ( ( strcmp( charBuf, "MONO" ) == 0 ) || ( strcmp( charBuf, "HOA0" ) == 0 ) || ( strcmp( charBuf, "SBA0" ) == 0 ) ) diff --git a/lib_com/options.h b/lib_com/options.h index 9cbf8bc338..de61db50a2 100755 --- a/lib_com/options.h +++ b/lib_com/options.h @@ -156,6 +156,9 @@ #define FIX_310_TD_REND_DELAY /* Adding HRTF delay being read from ROM/Binary file, fix rounding for delay compensation in renderer */ #define FIX_334_DEBUG_BE_STEREO_SWITCHING /* FhG: Fix non-BE issue for stereo switching when DEBUGGING is enabled */ +#define FIX_343_TO_UPPER /* VA: issue 343: safeguard for function to_upper() */ + + /* ################## End DEVELOPMENT switches ######################### */ /* clang-format on */ #endif -- GitLab