Commit 14702ee9 authored by Tapani Pihlajakuja's avatar Tapani Pihlajakuja
Browse files

Merge branch 'basop-2433-arithmetic-overflow-in-qmetadata-encoder' into 'main'

Fix 2433 Arithmetic overflow in qmetadata encode

See merge request !2823
parents 7291acfd c7f0fe7c
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -101,6 +101,7 @@
#define FIX_2346_DUPLICATED_IGF_FUNCTIONS               /* FhG: basop issue 2346: Review potentially duplicated IGF functions */
#define FIX_1525_UNINIT_FORMAT_SWITCHING_DEC            /* VA: float issue 1525: fix reading of uninitialized memory in format switching at the decoder */
#define HARMONIZE_2446_CON_TCX_FX                       /* FhG: basop issue: 2446 harmonization of function con_tcx_fx() */
#define FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC            /* Nokia: Fix to convert non-converted binary operations */

/* #################### End BE switches ################################## */

+87 −6
Original line number Diff line number Diff line
@@ -4663,14 +4663,28 @@ static Word16 encode_coherence_indexesDCT0_fx(
    move16();
    i = 0;
    move16();
#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC
    /* verify that idx and idx1 can be represented on 63 bits as it has been designed through split outside this function */
    assert( nbits < 63 );
    assert( nbits1 < 63 );
#endif
    FOR( i = 0; i < no_idx16 - 1; i++ )
    {
        k = sub( k, 16 );
#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC
        hMetaData->ind_list[indice_coherence + i].value = u_extract_l( (UWord32) W_extract_l( W_shr( idx, k ) ) ); /*   ( ( idx >> k ) & 65535 );  16 bits */
#else
        hMetaData->ind_list[indice_coherence + i].value = ( ( idx >> k ) & 65535 ); /* 16 bits */
        move16();
#endif
    }
#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC
    hMetaData->ind_list[indice_coherence + i].value = u_extract_l( (UWord32) L_and( W_extract_l( idx ), L_sub( L_shl( 1, k ), 1 ) ) ); /* ( idx & ( ( 1 << k ) - 1 ) ); */
#else
    hMetaData->ind_list[indice_coherence + i].value = ( idx & ( ( 1 << k ) - 1 ) );
    move16();
#endif


    IF( nbits1 > 0 )
    {
@@ -4691,11 +4705,19 @@ static Word16 encode_coherence_indexesDCT0_fx(
        FOR( j = i + 1; j < no_idx16 + i; j++ )
        {
            k = sub( k, 16 );
#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC
            hMetaData->ind_list[indice_coherence + j].value = u_extract_l( (UWord32) W_extract_l( W_shr( idx1, k ) ) ); /*   ( ( idx1 >> k ) & 65535 );   16 bits */
#else
            hMetaData->ind_list[indice_coherence + j].value = ( ( idx1 >> k ) & 65535 ); /* 16 bits */
            move16();
#endif
        }
#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC
        hMetaData->ind_list[indice_coherence + j].value = u_extract_l( (UWord32) L_and( W_extract_l( idx1 ), L_sub( L_shl( 1, k ), 1 ) ) ); /* ( idx1 & ( ( 1 << k ) - 1 ) ); */
#else
        hMetaData->ind_list[indice_coherence + j].value = ( idx1 & ( ( 1 << k ) - 1 ) );
        move16();
#endif
    }

    return add( nbits, nbits1 );
@@ -4965,16 +4987,28 @@ static Word16 encode_spread_coherence_1sf_fx(
            no_idx16 = shr_r( add( nbits_fr, ONE_IN_Q3 ), 4 );
        }

#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC
        /* verify that idx and idx1 can be represented on 63 bits as it has been designed through split outside this function */
        assert( nbits_fr < 63 );
        assert( nbits_fr1 < 63 );
#endif
        /* write combined index */
        k = nbits_fr;
        move16();
        FOR( i = 0; i < no_idx16 - 1; i++ )
        {
            k = sub( k, 16 );
#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC
            push_next_indice( hMasaMetaData, u_extract_l( (UWord32) W_extract_l( W_shr( idx, k ) ) ), 16 ); /*  ( ( idx >> k ) & 65535 );   16 bits */
#else
            push_next_indice( hMasaMetaData, ( ( idx >> k ) & 65535 ), 16 ); /* 16 bits */
#endif
        }

#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC
        push_next_indice( hMasaMetaData, u_extract_l( (UWord32) L_and( W_extract_l( idx ), L_sub( L_shl( 1, k ), 1 ) ) ), k ); /* ( idx & ( ( 1 << k ) - 1 ) ); */
#else
        push_next_indice( hMasaMetaData, ( idx & ( ( 1 << k ) - 1 ) ), k );
#endif

        IF( nbits_fr1 > 0 )
        {
@@ -4996,9 +5030,17 @@ static Word16 encode_spread_coherence_1sf_fx(
            FOR( i = 0; i < no_idx16 - 1; i++ )
            {
                k = sub( k, 16 );
#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC
                push_next_indice( hMasaMetaData, u_extract_l( (UWord32) W_extract_l( W_shr( idx1, k ) ) ), 16 ); /*  ( ( idx1 >> k ) & 65535 );   16 bits */
#else
                push_next_indice( hMasaMetaData, ( ( idx1 >> k ) & 65535 ), 16 ); /* 16 bits */
#endif
            }
#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC
            push_next_indice( hMasaMetaData, u_extract_l( (UWord32) L_and( W_extract_l( idx1 ), L_sub( L_shl( 1, k ), 1 ) ) ), k ); /* ( idx1 & ( ( 1 << k ) - 1 ) ); */
#else
            push_next_indice( hMasaMetaData, ( idx1 & ( ( 1 << k ) - 1 ) ), k );
#endif
        }
    }
    ELSE
@@ -5191,16 +5233,29 @@ static Word16 encode_surround_coherence_fx(
                no_idx16 = shr_r( add( nbits_fr, ONE_IN_Q3 ), 4 );
            }

#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC
            /* verify that idx and idx1 can be represented on 63 bits as it has been designed through split outside this function */
            assert( nbits_fr < 63 );
            assert( nbits_fr1 < 63 );
#endif

            /* write combined index */
            k = nbits_fr;
            move16();
            FOR( i = 0; i < no_idx16 - 1; i++ )
            {
                k = sub( k, 16 );
#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC
                push_next_indice( hMetaData, u_extract_l( (UWord32) W_extract_l( W_shr( idx, k ) ) ), 16 ); /*  ( ( idx >> k ) & 65535 );   16 bits */
#else
                push_next_indice( hMetaData, ( ( idx >> k ) & 65535 ), 16 ); /* 16 bits */
#endif
            }

#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC
            push_next_indice( hMetaData, u_extract_l( (UWord32) L_and( W_extract_l( idx ), L_sub( L_shl( 1, k ), 1 ) ) ), k ); /* ( idx & ( ( 1 << k ) - 1 ) ); */
#else
            push_next_indice( hMetaData, ( idx & ( ( 1 << k ) - 1 ) ), k );
#endif

            IF( nbits_fr1 > 0 )
            {
@@ -5222,10 +5277,17 @@ static Word16 encode_surround_coherence_fx(
                FOR( i = 0; i < no_idx16 - 1; i++ )
                {
                    k = sub( k, 16 );
#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC
                    push_next_indice( hMetaData, u_extract_l( (UWord32) W_extract_l( W_shr( idx1, k ) ) ), 16 ); /*  ( ( idx1 >> k ) & 65535 );   16 bits */
#else
                    push_next_indice( hMetaData, ( ( idx1 >> k ) & 65535 ), 16 ); /* 16 bits */
#endif
                }

#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC
                push_next_indice( hMetaData, u_extract_l( (UWord32) L_and( W_extract_l( idx1 ), L_sub( L_shl( 1, k ), 1 ) ) ), k ); /* ( idx1 & ( ( 1 << k ) - 1 ) ); */
#else
                push_next_indice( hMetaData, ( idx1 & ( ( 1 << k ) - 1 ) ), k );
#endif
            }
        }
        ELSE
@@ -5420,16 +5482,29 @@ static Word16 encode_surround_coherence_hr_fx(
                        no_idx16 = add( shr( nbits_fr, 4 ), 1 );
                    }

#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC
                    /* verify that idx and idx1 can be represented on 63 bits as it has been designed through split outside this function */
                    assert( nbits_fr < 63 );
                    assert( nbits_fr1 < 63 );
#endif

                    /* write combined index */
                    k = nbits_fr;
                    move16();
                    FOR( i = 0; i < no_idx16 - 1; i++ )
                    {
                        k = sub( k, 16 );
#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC
                        push_next_indice( hMetaData, u_extract_l( (UWord32) W_extract_l( W_shr( idx, k ) ) ), 16 ); /*  ( ( idx >> k ) & 65535 );   16 bits */
#else
                        push_next_indice( hMetaData, ( ( idx >> k ) & 65535 ), 16 ); /* 16 bits */
#endif
                    }

#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC
                    push_next_indice( hMetaData, u_extract_l( (UWord32) L_and( W_extract_l( idx ), L_sub( L_shl( 1, k ), 1 ) ) ), k ); /* ( idx & ( ( 1 << k ) - 1 ) ); */
#else
                    push_next_indice( hMetaData, ( idx & ( ( 1 << k ) - 1 ) ), k );
#endif

                    IF( nbits_fr1 > 0 )
                    {
@@ -5449,10 +5524,17 @@ static Word16 encode_surround_coherence_hr_fx(
                        FOR( i = 0; i < no_idx16 - 1; i++ )
                        {
                            k = sub( k, 16 );
#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC
                            push_next_indice( hMetaData, u_extract_l( (UWord32) W_extract_l( W_shr( idx1, k ) ) ), 16 ); /*  ( ( idx1 >> k ) & 65535 );   16 bits */
#else
                            push_next_indice( hMetaData, ( ( idx1 >> k ) & 65535 ), 16 ); /* 16 bits */
#endif
                        }

#ifdef FIX_2433_ARITH_OVERFLOW_IN_QMETA_ENC
                        push_next_indice( hMetaData, u_extract_l( (UWord32) L_and( W_extract_l( idx1 ), L_sub( L_shl( 1, k ), 1 ) ) ), k ); /* ( idx1 & ( ( 1 << k ) - 1 ) ); */
#else
                        push_next_indice( hMetaData, ( idx1 & ( ( 1 << k ) - 1 ) ), k );
#endif
                    }
                }
                ELSE
@@ -6708,6 +6790,5 @@ void ivas_omasa_encode_masa_to_total_fx(
    }
    assert( nb_bits == ( hMetaData->nb_bits_tot - bits_pos ) );


    return;
}