Commit e2e9a459 authored by sagnowski's avatar sagnowski
Browse files

Add validity checks for quaternions at the API boundary

parent 2b2b178a
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -93,6 +93,9 @@ typedef enum
    IVAS_ERR_IO_CONFIG_PAIR_NOT_SUPPORTED,
    IVAS_ERR_TSM_NOT_ENABLED,
    IVAS_ERR_FETCH_SIZE_NO_MULTIPLE_OF_5MS,
#ifdef FIX_FLOAT_1529_VALIDATE_QUATERNIONS
    IVAS_ERR_INVALID_QUATERNION,
#endif
#ifdef DEBUGGING
    IVAS_ERR_INVALID_FORCE_MODE,
#ifdef DEBUG_AGC_ENCODER_CMD_OPTION
+5 −0
Original line number Diff line number Diff line
@@ -827,6 +827,11 @@ void QuaternionInverse(
);


#ifdef FIX_FLOAT_1529_VALIDATE_QUATERNIONS
ivas_error validate_quaternion( IVAS_QUATERNION q );
#endif


/*----------------------------------------------------------------------------------*
 * Internal rendering prototypes
 *----------------------------------------------------------------------------------*/
+70 −0
Original line number Diff line number Diff line
/******************************************************************************************************

   (C) 2022-2026 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB,
   Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
   Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
   Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
   contributors to this repository. All Rights Reserved.

   This software is protected by copyright law and by international treaties.
   The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB,
   Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD.,
   Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange,
   Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other
   contributors to this repository retain full ownership rights in their respective contributions in
   the software. This notice grants no license of any kind, including but not limited to patent
   license, nor is any license granted by implication, estoppel or otherwise.

   Contributors are required to enter into the IVAS codec Public Collaboration agreement before making
   contributions.

   This software is provided "AS IS", without any express or implied warranties. The software is in the
   development stage. It is intended exclusively for experts who have experience with such software and
   solely for the purpose of inspection. All implied warranties of non-infringement, merchantability
   and fitness for a particular purpose are hereby disclaimed and excluded.

   Any dispute, controversy or claim arising under or in relation to providing this software shall be
   submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in
   accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and
   the United Nations Convention on Contracts on the International Sales of Goods.

*******************************************************************************************************/

#include "options.h"
#include "ivas_prot.h"
#include <math.h>

#ifdef FIX_FLOAT_1529_VALIDATE_QUATERNIONS
/*---------------------------------------------------------------------*
 * validate_quaternion( )
 *
 * Ensures given quaternion has close to unit norm.
 * If Euler angles (w == -3), checks if angles are within reasonable ranges.
 *---------------------------------------------------------------------*/
ivas_error validate_quaternion( IVAS_QUATERNION q )
{
    float norm_squared;
    float epsilon;

    epsilon = 1e-5f;

    // Euler angles if w == -3
    if ( q.w == -3.0f &&
         ( q.x < -180.0f || 180.0f < q.x    // yaw out of range
           || q.y < -90.0f || 90.0f < q.y   // pitch out of range
           || q.z < -180.0f || 180.0f < q.z // roll out of range
           ) )
    {
        return IVAS_ERR_INVALID_QUATERNION;
    }

    norm_squared = q.w * q.w + q.x * q.x + q.y * q.y + q.z * q.z;
    if ( fabsf( norm_squared - 1.0f ) < epsilon )
    {
        return IVAS_ERR_INVALID_QUATERNION;
    }

    return IVAS_ERR_OK;
}
#endif
+1 −0
Original line number Diff line number Diff line
@@ -164,6 +164,7 @@
#define FIX_2235_TD_RENDERER_WORD16                     /* Eri: For float: small synch with BASOP, removing unnecessary abs. BASOP: Use Word16 in TD renderer without converting to Word32 */
#define FIX_FLOAT_1526_DIRAC_MEM_LEAK                   /* FhG: potential memory leak in DirAC handles in case of format switching */
#define ALIGN_ACELP_CORE                                /* VA: align ACELP core functions with BASOP */
#define FIX_FLOAT_1529_VALIDATE_QUATERNIONS             /* FhG: validate quaternion inputs at API boundary */

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

+27 −0
Original line number Diff line number Diff line
@@ -2582,6 +2582,13 @@ ivas_error IVAS_DEC_FeedHeadTrackData(
        return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    }

#ifdef FIX_FLOAT_1529_VALIDATE_QUATERNIONS
    if ( ( error = validate_quaternion( orientation ) ) != IVAS_ERR_OK )
    {
        return error;
    }
#endif

    hHeadTrackData = hIvasDec->st_ivas->hHeadTrackData;

    if ( hHeadTrackData == NULL )
@@ -2624,12 +2631,22 @@ ivas_error IVAS_DEC_FeedRefRotData(
)
{
    ivas_orient_trk_state_t *pOtr;
#ifdef FIX_FLOAT_1529_VALIDATE_QUATERNIONS
    ivas_error error;
#endif

    if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL || hIvasDec->st_ivas->hHeadTrackData == NULL || hIvasDec->st_ivas->hHeadTrackData->OrientationTracker == NULL )
    {
        return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    }

#ifdef FIX_FLOAT_1529_VALIDATE_QUATERNIONS
    if ( ( error = validate_quaternion( rotation ) ) != IVAS_ERR_OK )
    {
        return error;
    }
#endif

    pOtr = hIvasDec->st_ivas->hHeadTrackData->OrientationTracker;

    pOtr->refRot.w = rotation.w;
@@ -2689,12 +2706,22 @@ ivas_error IVAS_DEC_FeedExternalOrientationData(
)
{
    EXTERNAL_ORIENTATION_HANDLE hExternalOrientationData;
#ifdef FIX_FLOAT_1529_VALIDATE_QUATERNIONS
    ivas_error error;
#endif

    if ( hIvasDec == NULL || hIvasDec->st_ivas == NULL )
    {
        return IVAS_ERR_UNEXPECTED_NULL_POINTER;
    }

#ifdef FIX_FLOAT_1529_VALIDATE_QUATERNIONS
    if ( ( error = validate_quaternion( orientation ) ) != IVAS_ERR_OK )
    {
        return error;
    }
#endif

    hExternalOrientationData = hIvasDec->st_ivas->hExtOrientationData;

    if ( hExternalOrientationData == NULL )
Loading