From b325367b332525e82ab331e3750a955a0679529a Mon Sep 17 00:00:00 2001 From: Fraunhofer IIS FDK Date: Fri, 8 Jun 2018 18:08:57 +0200 Subject: Unsigned Integer Overflow in SpatialDecParseSpecificConfigHeader(). Bug: 112661893 Test: atest DecoderTestXheAac ; atest DecoderTestAacDrc Change-Id: I5994a55f993835fa511ff61a337726b3e51aed5d --- libSACdec/src/sac_bitdec.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libSACdec/src') diff --git a/libSACdec/src/sac_bitdec.cpp b/libSACdec/src/sac_bitdec.cpp index 37e0cf2..45fb17a 100644 --- a/libSACdec/src/sac_bitdec.cpp +++ b/libSACdec/src/sac_bitdec.cpp @@ -291,13 +291,13 @@ SACDEC_ERROR SpatialDecParseSpecificConfigHeader( if (sacHeaderLen == 127) { sacHeaderLen += FDKreadBits(bitstream, 16); } - numFillBits = FDKgetValidBits(bitstream); + numFillBits = (INT)FDKgetValidBits(bitstream); err = SpatialDecParseSpecificConfig(bitstream, pSpatialSpecificConfig, sacHeaderLen, coreCodec); numFillBits -= - FDKgetValidBits(bitstream); /* the number of read bits (tmpBits) */ + (INT)FDKgetValidBits(bitstream); /* the number of read bits (tmpBits) */ numFillBits = (8 * sacHeaderLen) - numFillBits; if (numFillBits < 0) { /* Parsing went wrong */ -- cgit v1.2.3 From bfa96f60bc607f64f865c9a77b8d896f8250e3b8 Mon Sep 17 00:00:00 2001 From: Fraunhofer IIS FDK Date: Fri, 8 Jun 2018 18:15:03 +0200 Subject: Unsigned Integer Overflows in mpegSurroundDecoder_Parse(). Bug: 112661835 Test: atest DecoderTestXheAac ; atest DecoderTestAacDrc Change-Id: I3714e88d7a9a866297bb2e93571804665a97773f --- libSACdec/src/sac_dec_lib.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'libSACdec/src') diff --git a/libSACdec/src/sac_dec_lib.cpp b/libSACdec/src/sac_dec_lib.cpp index ebf9bee..5ae89d1 100644 --- a/libSACdec/src/sac_dec_lib.cpp +++ b/libSACdec/src/sac_dec_lib.cpp @@ -1232,7 +1232,7 @@ int mpegSurroundDecoder_Parse(CMpegSurroundDecoder *pMpegSurroundDecoder, FDK_ASSERT(pMpegSurroundDecoder->pSpatialDec); - mpsBsBits = FDKgetValidBits(hBs); + mpsBsBits = (INT)FDKgetValidBits(hBs); sscParse = &pMpegSurroundDecoder ->spatialSpecificConfig[pMpegSurroundDecoder->bsFrameParse]; @@ -1308,14 +1308,14 @@ int mpegSurroundDecoder_Parse(CMpegSurroundDecoder *pMpegSurroundDecoder, pMpegSurroundDecoder->spatialSpecificConfigBackup; /* Parse spatial specific config */ - bitsRead = FDKgetValidBits(hMpsBsData); + bitsRead = (INT)FDKgetValidBits(hMpsBsData); err = SpatialDecParseSpecificConfigHeader( hMpsBsData, &pMpegSurroundDecoder->spatialSpecificConfigBackup, coreCodec, pMpegSurroundDecoder->upmixType); - bitsRead = (bitsRead - FDKgetValidBits(hMpsBsData)); + bitsRead = (bitsRead - (INT)FDKgetValidBits(hMpsBsData)); parseResult = ((err == MPS_OK) ? bitsRead : -bitsRead); if (parseResult < 0) { @@ -1429,7 +1429,7 @@ int mpegSurroundDecoder_Parse(CMpegSurroundDecoder *pMpegSurroundDecoder, bail: - *pMpsDataBits -= (mpsBsBits - FDKgetValidBits(hBs)); + *pMpsDataBits -= (mpsBsBits - (INT)FDKgetValidBits(hBs)); return err; } -- cgit v1.2.3 From 64134e60b348bb1686986e217f4020d6d108ed46 Mon Sep 17 00:00:00 2001 From: Fraunhofer IIS FDK Date: Fri, 19 Oct 2018 16:37:31 +0200 Subject: Add FDK_FALLTHROUGH macro to prevent implicit-fallthrough compiler warnings Test: atest DecoderTestXheAac ; atest DecoderTestAacDrc Change-Id: I9f9064fb63ac40e18f245c00b7375b4874f2925b --- libAACdec/src/aacdecoder.cpp | 7 ++++++- libAACdec/src/channel.cpp | 1 + libAACdec/src/conceal.cpp | 1 + libAACenc/src/aacenc_lib.cpp | 3 +++ libAACenc/src/bitenc.cpp | 2 ++ libMpegTPDec/src/tpdec_asc.cpp | 13 +++++++++++-- libMpegTPDec/src/tpdec_lib.cpp | 1 + libMpegTPEnc/src/tpenc_lib.cpp | 1 + libPCMutils/src/pcmdmx_lib.cpp | 3 +++ libSACdec/src/sac_dec_lib.cpp | 1 + libSYS/include/machine_type.h | 11 +++++++++++ 11 files changed, 41 insertions(+), 3 deletions(-) (limited to 'libSACdec/src') diff --git a/libAACdec/src/aacdecoder.cpp b/libAACdec/src/aacdecoder.cpp index 8993927..c2ddc48 100644 --- a/libAACdec/src/aacdecoder.cpp +++ b/libAACdec/src/aacdecoder.cpp @@ -234,7 +234,8 @@ void CAacDecoder_SyncQmfMode(HANDLE_AACDECODER self) { MODE_HQ))) { /* MPS decoder does support the requested mode. */ break; } - } /* Fall-through: */ + } + FDK_FALLTHROUGH; default: if (self->qmfModeUser == NOT_DEFINED) { /* Revert in case mpegSurroundDecoder_SetParam() fails. */ @@ -938,6 +939,7 @@ static AAC_DECODER_ERROR CAacDecoder_ExtPayloadParse( case EXT_SBR_DATA_CRC: crcFlag = 1; + FDK_FALLTHROUGH; case EXT_SBR_DATA: if (IS_CHANNEL_ELEMENT(previous_element)) { SBR_ERROR sbrError; @@ -1076,6 +1078,7 @@ static AAC_DECODER_ERROR CAacDecoder_ExtPayloadParse( * intentional. */ break; } + FDK_FALLTHROUGH; case EXT_FIL: @@ -1495,11 +1498,13 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc, switch (asc->m_aot) { case AOT_AAC_LC: self->streamInfo.profile = 1; + FDK_FALLTHROUGH; case AOT_ER_AAC_SCAL: if (asc->m_sc.m_gaSpecificConfig.m_layer > 0) { /* aac_scalable_extension_element() currently not supported. */ return AAC_DEC_UNSUPPORTED_FORMAT; } + FDK_FALLTHROUGH; case AOT_SBR: case AOT_PS: case AOT_ER_AAC_LC: diff --git a/libAACdec/src/channel.cpp b/libAACdec/src/channel.cpp index cfffd57..a020034 100644 --- a/libAACdec/src/channel.cpp +++ b/libAACdec/src/channel.cpp @@ -592,6 +592,7 @@ AAC_DECODER_ERROR CChannelElement_Read( line: ~599 */ /* Note: The missing "break" is intentional here, since we need to call * CBlock_ReadScaleFactorData(). */ + FDK_FALLTHROUGH; case scale_factor_data: if (flags & AC_ER_RVLC) { diff --git a/libAACdec/src/conceal.cpp b/libAACdec/src/conceal.cpp index a6064b6..cc6de75 100644 --- a/libAACdec/src/conceal.cpp +++ b/libAACdec/src/conceal.cpp @@ -1894,6 +1894,7 @@ INT CConcealment_TDFading( case ConcealState_FadeIn: idx = cntFadeFrames; idx -= TDFadeInStopBeforeFullLevel; + FDK_FALLTHROUGH; case ConcealState_Ok: fadeFactor = pConcealParams->fadeInFactor; idx = (concealState == ConcealState_Ok) ? -1 : idx; diff --git a/libAACenc/src/aacenc_lib.cpp b/libAACenc/src/aacenc_lib.cpp index f92cff4..9e0630c 100644 --- a/libAACenc/src/aacenc_lib.cpp +++ b/libAACenc/src/aacenc_lib.cpp @@ -907,6 +907,7 @@ static AACENC_ERROR FDKaacEnc_AdjustEncSettings(HANDLE_AACENCODER hAacEncoder, case AOT_MP2_AAC_LC: case AOT_MP2_SBR: hAacConfig->usePns = 0; + FDK_FALLTHROUGH; case AOT_AAC_LC: case AOT_SBR: case AOT_PS: @@ -2091,12 +2092,14 @@ AACENC_ERROR aacEncoder_SetParam(const HANDLE_AACENCODER hAacEncoder, err = AACENC_INVALID_CONFIG; goto bail; } + FDK_FALLTHROUGH; case AOT_SBR: case AOT_MP2_SBR: if (!(hAacEncoder->encoder_modis & (ENC_MODE_FLAG_SBR))) { err = AACENC_INVALID_CONFIG; goto bail; } + FDK_FALLTHROUGH; case AOT_AAC_LC: case AOT_MP2_AAC_LC: case AOT_ER_AAC_LD: diff --git a/libAACenc/src/bitenc.cpp b/libAACenc/src/bitenc.cpp index 652d1fd..957e821 100644 --- a/libAACenc/src/bitenc.cpp +++ b/libAACenc/src/bitenc.cpp @@ -643,6 +643,7 @@ static INT FDKaacEnc_writeExtensionPayload(HANDLE_FDK_BITSTREAM hBitStream, FDKwriteBits(hBitStream, *extPayloadData++, 4); /* nibble */ } extBitsUsed += 4; + FDK_FALLTHROUGH; case EXT_DYNAMIC_RANGE: case EXT_SBR_DATA: case EXT_SBR_DATA_CRC: @@ -690,6 +691,7 @@ static INT FDKaacEnc_writeExtensionPayload(HANDLE_FDK_BITSTREAM hBitStream, case EXT_FILL_DATA: fillByte = 0xA5; + FDK_FALLTHROUGH; case EXT_FIL: default: if (hBitStream != NULL) { diff --git a/libMpegTPDec/src/tpdec_asc.cpp b/libMpegTPDec/src/tpdec_asc.cpp index 8d411e8..6260cad 100644 --- a/libMpegTPDec/src/tpdec_asc.cpp +++ b/libMpegTPDec/src/tpdec_asc.cpp @@ -467,6 +467,7 @@ void CProgramConfig_GetDefault(CProgramConfig *pPce, const UINT channelConfig) { pPce->BackElementIsCpe[1] = 1; pPce->NumChannels += 1; pPce->NumEffectiveChannels += 1; + FDK_FALLTHROUGH; case 11: /* 3/0/3.1ch */ pPce->NumFrontChannelElements += 2; pPce->FrontElementIsCpe[0] = 0; @@ -482,25 +483,30 @@ void CProgramConfig_GetDefault(CProgramConfig *pPce, const UINT channelConfig) { /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ case 14: /* 2/0/0-3/0/2-0.1ch front height */ pPce->FrontElementHeightInfo[2] = 1; /* Top speaker */ - case 7: /* 5/0/2.1ch front */ + FDK_FALLTHROUGH; + case 7: /* 5/0/2.1ch front */ pPce->NumFrontChannelElements += 1; pPce->FrontElementIsCpe[2] = 1; pPce->NumChannels += 2; pPce->NumEffectiveChannels += 2; + FDK_FALLTHROUGH; case 6: /* 3/0/2.1ch */ pPce->NumLfeChannelElements += 1; pPce->NumChannels += 1; + FDK_FALLTHROUGH; case 5: /* 3/0/2.0ch */ case 4: /* 3/0/1.0ch */ pPce->NumBackChannelElements += 1; pPce->BackElementIsCpe[0] = (channelConfig > 4) ? 1 : 0; pPce->NumChannels += (channelConfig > 4) ? 2 : 1; pPce->NumEffectiveChannels += (channelConfig > 4) ? 2 : 1; + FDK_FALLTHROUGH; case 3: /* 3/0/0.0ch */ pPce->NumFrontChannelElements += 1; pPce->FrontElementIsCpe[1] = 1; pPce->NumChannels += 2; pPce->NumEffectiveChannels += 2; + FDK_FALLTHROUGH; case 1: /* 1/0/0.0ch */ pPce->NumFrontChannelElements += 1; pPce->FrontElementIsCpe[0] = 0; @@ -713,6 +719,7 @@ int CProgramConfig_LookupElement(CProgramConfig *pPce, UINT channelConfig, switch (elType) { case ID_CPE: isCpe = 1; + FDK_FALLTHROUGH; case ID_SCE: /* search in front channels */ for (i = 0; i < pPce->NumFrontChannelElements; i++) { @@ -1412,7 +1419,7 @@ static TRANSPORTDEC_ERROR EldSpecificConfig_Parse(CSAudioSpecificConfig *asc, break; } - /* fall-through */ + FDK_FALLTHROUGH; default: for (cnt = 0; cnt < eldExtLen; cnt++) { FDKreadBits(hBs, 8); @@ -2022,6 +2029,7 @@ static TRANSPORTDEC_ERROR AudioSpecificConfig_ExtensionParse( break; case ASCEXT_MPS: /* 0x76a */ if (self->m_extensionAudioObjectType == AOT_MPEGS) break; + FDK_FALLTHROUGH; case ASCEXT_LDMPS: /* 0x7cc */ if ((ascExtId == ASCEXT_LDMPS) && (self->m_extensionAudioObjectType == AOT_LD_MPEGS)) @@ -2498,6 +2506,7 @@ TRANSPORTDEC_ERROR DrmRawSdcAudioConfig_Parse( switch (audioMode) { case 1: /* parametric stereo */ self->m_psPresentFlag = 1; + FDK_FALLTHROUGH; case 0: /* mono */ self->m_channelConfiguration = 1; break; diff --git a/libMpegTPDec/src/tpdec_lib.cpp b/libMpegTPDec/src/tpdec_lib.cpp index 2a40187..1976cb9 100644 --- a/libMpegTPDec/src/tpdec_lib.cpp +++ b/libMpegTPDec/src/tpdec_lib.cpp @@ -956,6 +956,7 @@ static TRANSPORTDEC_ERROR transportDec_readHeader( hTp->parser.latm.m_audioMuxLengthBytes = syncLayerFrameBits; syncLayerFrameBits <<= 3; } + FDK_FALLTHROUGH; case TT_MP4_LATM_MCP1: case TT_MP4_LATM_MCP0: if (hTp->numberOfRawDataBlocks <= 0) { diff --git a/libMpegTPEnc/src/tpenc_lib.cpp b/libMpegTPEnc/src/tpenc_lib.cpp index a8567b9..14ea5fe 100644 --- a/libMpegTPEnc/src/tpenc_lib.cpp +++ b/libMpegTPEnc/src/tpenc_lib.cpp @@ -212,6 +212,7 @@ static INT getPceRepetitionRate(const CHANNEL_MODE channelMode, for potential matrix mixdown */ break; } + FDK_FALLTHROUGH; case TT_MP4_LOAS: /* PCE in ASC if chChonfig==0 */ case TT_MP4_LATM_MCP1: /* PCE in ASC if chChonfig==0 */ default: diff --git a/libPCMutils/src/pcmdmx_lib.cpp b/libPCMutils/src/pcmdmx_lib.cpp index b09a848..2070dbc 100644 --- a/libPCMutils/src/pcmdmx_lib.cpp +++ b/libPCMutils/src/pcmdmx_lib.cpp @@ -1043,6 +1043,7 @@ static PCMDMX_ERROR getMixFactors(const UCHAR inModeIsCfg, case CH_MODE_3_2_1_0: isValidCfg = FALSE; err = PCMDMX_INVALID_MODE; + FDK_FALLTHROUGH; case CH_MODE_3_0_3_1: /* chCfg 11 */ /* 6.1ch: C' = C; L' = L; R' = R; LFE' = LFE; Ls' = Ls*dmix_a_idx + Cs*dmix_b_idx; @@ -1080,9 +1081,11 @@ static PCMDMX_ERROR getMixFactors(const UCHAR inModeIsCfg, LEFT_REAR_CHANNEL, FL2FXCONST_DMX(0.5f), 1); dmxSetChannel(mixFactors, mixScales, LEFT_REAR_CHANNEL, LEFT_REAR_CHANNEL, FL2FXCONST_DMX(0.5f), 1); + FDK_FALLTHROUGH; case CH_MODE_5_2_1_0: isValidCfg = FALSE; err = PCMDMX_INVALID_MODE; + FDK_FALLTHROUGH; case CH_MODE_5_0_2_1: /* chCfg 7 || 14 */ if (inChCfg == 14) { /* 7.1ch Front Height: C' = C; Ls' = Ls; Rs' = Rs; LFE' = LFE; diff --git a/libSACdec/src/sac_dec_lib.cpp b/libSACdec/src/sac_dec_lib.cpp index 5ae89d1..e881599 100644 --- a/libSACdec/src/sac_dec_lib.cpp +++ b/libSACdec/src/sac_dec_lib.cpp @@ -1349,6 +1349,7 @@ int mpegSurroundDecoder_Parse(CMpegSurroundDecoder *pMpegSurroundDecoder, pMpegSurroundDecoder->mpegSurroundSscIsGlobalCfg = 0; } } + FDK_FALLTHROUGH; case MPEGS_ANCTYPE_FRAME: if (pMpegSurroundDecoder diff --git a/libSYS/include/machine_type.h b/libSYS/include/machine_type.h index be8de37..b66d5ad 100644 --- a/libSYS/include/machine_type.h +++ b/libSYS/include/machine_type.h @@ -379,6 +379,17 @@ it. Hence, a fully platform-independant way to use alignment is not supported. #define LNK_SECTION_L1_DATA_A #define LNK_SECTION_L1_DATA_B +/************************************************** + * Macros regarding static code analysis + **************************************************/ +#if defined(__clang__) +#define FDK_FALLTHROUGH [[clang::fallthrough]] +#elif defined(__GNUC__) && (__GNUC__ >= 7) +#define FDK_FALLTHROUGH __attribute__((fallthrough)) +#else +#define FDK_FALLTHROUGH +#endif + #ifdef _MSC_VER /* * Sometimes certain features are excluded from compilation and therefore the -- cgit v1.2.3 From c371e86ef4d4a6a68e8139e00745faeb8c2c82ba Mon Sep 17 00:00:00 2001 From: Fraunhofer IIS FDK Date: Thu, 20 Dec 2018 15:52:46 +0100 Subject: QMF configuration flag QMF_FLAG_MPSLDFB has always priority over QMF_FLAG_CLDFB Test: atest DecoderTestXheAac ; atest DecoderTestAacDrc Change-Id: I7c851b9db88c6250b5ad30282b8b19ea306e4e12 --- libFDK/src/FDK_qmf_domain.cpp | 8 ++++---- libSACdec/src/sac_dec_lib.cpp | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'libSACdec/src') diff --git a/libFDK/src/FDK_qmf_domain.cpp b/libFDK/src/FDK_qmf_domain.cpp index 409f222..dd63dab 100644 --- a/libFDK/src/FDK_qmf_domain.cpp +++ b/libFDK/src/FDK_qmf_domain.cpp @@ -889,10 +889,6 @@ QMF_DOMAIN_ERROR FDK_QmfDomain_Configure(HANDLE_FDK_QMF_DOMAIN hqd) { !(hgc->flags & (QMF_FLAG_CLDFB | QMF_FLAG_MPSLDFB))) { hgc->flags_requested |= QMF_FLAG_DOWNSAMPLED; } - if ((hgc->flags_requested & QMF_FLAG_MPSLDFB) && - (hgc->flags_requested & QMF_FLAG_CLDFB)) { - hgc->flags_requested &= ~QMF_FLAG_CLDFB; - } hasChanged = 1; } @@ -901,6 +897,10 @@ QMF_DOMAIN_ERROR FDK_QmfDomain_Configure(HANDLE_FDK_QMF_DOMAIN hqd) { /* 5. set requested flags */ if (hgc->flags != hgc->flags_requested) { + if ((hgc->flags_requested & QMF_FLAG_MPSLDFB) && + (hgc->flags_requested & QMF_FLAG_CLDFB)) { + hgc->flags_requested &= ~QMF_FLAG_CLDFB; + } hgc->flags = hgc->flags_requested; hasChanged = 1; } diff --git a/libSACdec/src/sac_dec_lib.cpp b/libSACdec/src/sac_dec_lib.cpp index e881599..7549e51 100644 --- a/libSACdec/src/sac_dec_lib.cpp +++ b/libSACdec/src/sac_dec_lib.cpp @@ -1087,6 +1087,7 @@ mpegSurroundDecoder_ConfigureQmfDomain( if (coreCodec == AOT_ER_AAC_ELD) { pGC->flags_requested |= QMF_FLAG_MPSLDFB; + pGC->flags_requested &= ~QMF_FLAG_CLDFB; } return err; -- cgit v1.2.3 From 80fa8b8067dc7e92f8d70cf0a2fe7c7c65555409 Mon Sep 17 00:00:00 2001 From: Fraunhofer IIS FDK Date: Thu, 20 Dec 2018 15:52:46 +0100 Subject: Clear spatial specific config struct at the beginning of parse routines Test: atest DecoderTestXheAac ; atest DecoderTestAacDrc Change-Id: I6e198942f3a065de9615eac544fdc73120d24b1e --- libSACdec/src/sac_bitdec.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'libSACdec/src') diff --git a/libSACdec/src/sac_bitdec.cpp b/libSACdec/src/sac_bitdec.cpp index 45fb17a..159cf84 100644 --- a/libSACdec/src/sac_bitdec.cpp +++ b/libSACdec/src/sac_bitdec.cpp @@ -325,6 +325,8 @@ SACDEC_ERROR SpatialDecParseMps212Config( INT coreSbrFrameLengthIndex) { int i; + FDKmemclear(pSpatialSpecificConfig, sizeof(SPATIAL_SPECIFIC_CONFIG)); + pSpatialSpecificConfig->stereoConfigIndex = stereoConfigIndex; pSpatialSpecificConfig->coreSbrFrameLengthIndex = coreSbrFrameLengthIndex; pSpatialSpecificConfig->freqRes = @@ -447,6 +449,8 @@ SACDEC_ERROR SpatialDecParseSpecificConfig( int numHeaderBits; int cfgStartPos, bitsAvailable; + FDKmemclear(pSpatialSpecificConfig, sizeof(SPATIAL_SPECIFIC_CONFIG)); + cfgStartPos = FDKgetValidBits(bitstream); /* It might be that we do not know the SSC length beforehand. */ if (sacHeaderLen == 0) { -- cgit v1.2.3 From 4a22282fe0cbf79555ea4535fa9723966509912a Mon Sep 17 00:00:00 2001 From: Fraunhofer IIS FDK Date: Thu, 20 Dec 2018 15:52:46 +0100 Subject: Add sanity check in SpatialDecParseSpecificConfig() Test: atest DecoderTestXheAac ; atest DecoderTestAacDrc Change-Id: I0249f75839829fdbc96218425e59ad914f9dfeda --- libSACdec/src/sac_bitdec.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'libSACdec/src') diff --git a/libSACdec/src/sac_bitdec.cpp b/libSACdec/src/sac_bitdec.cpp index 159cf84..da5b262 100644 --- a/libSACdec/src/sac_bitdec.cpp +++ b/libSACdec/src/sac_bitdec.cpp @@ -572,16 +572,18 @@ SACDEC_ERROR SpatialDecParseSpecificConfig( numHeaderBits = cfgStartPos - (INT)FDKgetValidBits(bitstream); bitsAvailable -= numHeaderBits; + if (bitsAvailable < 0) { + err = MPS_PARSE_ERROR; + goto bail; + } pSpatialSpecificConfig->sacExtCnt = 0; pSpatialSpecificConfig->bResidualCoding = 0; - if ((err == MPS_OK) && (bitsAvailable > 0)) { - err = SpatialDecParseExtensionConfig( - bitstream, pSpatialSpecificConfig, pSpatialSpecificConfig->nOttBoxes, - pSpatialSpecificConfig->nTttBoxes, - pSpatialSpecificConfig->nOutputChannels, bitsAvailable); - } + err = SpatialDecParseExtensionConfig( + bitstream, pSpatialSpecificConfig, pSpatialSpecificConfig->nOttBoxes, + pSpatialSpecificConfig->nTttBoxes, + pSpatialSpecificConfig->nOutputChannels, bitsAvailable); FDKbyteAlign( bitstream, -- cgit v1.2.3 From f440f28aa3cfa02d52abb89e7db24d16f6eb0172 Mon Sep 17 00:00:00 2001 From: Fraunhofer IIS FDK Date: Thu, 20 Dec 2018 15:52:46 +0100 Subject: Return SpatialDecDecodeFrame() parse error in case extended frame does not match the spatial frame Test: atest DecoderTestXheAac ; atest DecoderTestAacDrc Change-Id: I7add6dff3b60ba0b36e5c83cee8031b37e970890 --- libSACdec/src/sac_bitdec.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'libSACdec/src') diff --git a/libSACdec/src/sac_bitdec.cpp b/libSACdec/src/sac_bitdec.cpp index da5b262..1049c3d 100644 --- a/libSACdec/src/sac_bitdec.cpp +++ b/libSACdec/src/sac_bitdec.cpp @@ -1870,6 +1870,16 @@ SACDEC_ERROR SpatialDecDecodeFrame(spatialDec *self, SPATIAL_BS_FRAME *frame) { frame->numParameterSets = fixMin(MAX_PARAMETER_SETS, frame->numParameterSets + 1); frame->paramSlot[frame->numParameterSets - 1] = self->timeSlots - 1; + + for (int p = 0; p < frame->numParameterSets; p++) { + if (frame->paramSlot[p] > self->timeSlots - 1) { + frame->paramSlot[p] = self->timeSlots - 1; + err = MPS_PARSE_ERROR; + } + } + if (err != MPS_OK) { + goto bail; + } } bail: -- cgit v1.2.3 From 5c54fa53876a92d4c7b923c5a6312f427cfc8c86 Mon Sep 17 00:00:00 2001 From: Fraunhofer IIS FDK Date: Thu, 20 Dec 2018 15:52:46 +0100 Subject: Add AOT specific number of qmf bands sanity check in SpatialSpecificConfig() Test: atest DecoderTestXheAac ; atest DecoderTestAacDrc Change-Id: Ic106c4371c5ac17cb832c7d9db042bcc9d1e7a09 --- libAACdec/src/aacdecoder_lib.cpp | 6 +- libAACenc/src/aacenc_lib.cpp | 3 +- libMpegTPDec/include/tp_data.h | 3 +- libMpegTPDec/src/tpdec_asc.cpp | 27 ++++++-- libMpegTPEnc/include/tp_data.h | 3 +- libMpegTPEnc/src/tpenc_asc.cpp | 4 +- libSACdec/include/sac_dec_lib.h | 6 +- libSACdec/src/sac_bitdec.cpp | 4 ++ libSACdec/src/sac_dec_lib.cpp | 138 +++++++++++++++++++++++++++++---------- 9 files changed, 144 insertions(+), 50 deletions(-) (limited to 'libSACdec/src') diff --git a/libAACdec/src/aacdecoder_lib.cpp b/libAACdec/src/aacdecoder_lib.cpp index 2860bf6..cbcd404 100644 --- a/libAACdec/src/aacdecoder_lib.cpp +++ b/libAACdec/src/aacdecoder_lib.cpp @@ -387,7 +387,7 @@ static INT aacDecoder_SbrCallback( static INT aacDecoder_SscCallback(void *handle, HANDLE_FDK_BITSTREAM hBs, const AUDIO_OBJECT_TYPE coreCodec, - const INT samplingRate, + const INT samplingRate, const INT frameSize, const INT stereoConfigIndex, const INT coreSbrFrameLengthIndex, const INT configBytes, const UCHAR configMode, @@ -398,8 +398,8 @@ static INT aacDecoder_SscCallback(void *handle, HANDLE_FDK_BITSTREAM hBs, err = mpegSurroundDecoder_Config( (CMpegSurroundDecoder *)hAacDecoder->pMpegSurroundDecoder, hBs, coreCodec, - samplingRate, stereoConfigIndex, coreSbrFrameLengthIndex, configBytes, - configMode, configChanged); + samplingRate, frameSize, stereoConfigIndex, coreSbrFrameLengthIndex, + configBytes, configMode, configChanged); switch (err) { case MPS_UNSUPPORTED_CONFIG: diff --git a/libAACenc/src/aacenc_lib.cpp b/libAACenc/src/aacenc_lib.cpp index 9e0630c..08cd57a 100644 --- a/libAACenc/src/aacenc_lib.cpp +++ b/libAACenc/src/aacenc_lib.cpp @@ -1216,7 +1216,8 @@ static INT aacenc_SbrCallback(void *self, HANDLE_FDK_BITSTREAM hBs, INT aacenc_SscCallback(void *self, HANDLE_FDK_BITSTREAM hBs, const AUDIO_OBJECT_TYPE coreCodec, - const INT samplingRate, const INT stereoConfigIndex, + const INT samplingRate, const INT frameSize, + const INT stereoConfigIndex, const INT coreSbrFrameLengthIndex, const INT configBytes, const UCHAR configMode, UCHAR *configChanged) { HANDLE_AACENCODER hAacEncoder = (HANDLE_AACENCODER)self; diff --git a/libMpegTPDec/include/tp_data.h b/libMpegTPDec/include/tp_data.h index b4ab802..b015332 100644 --- a/libMpegTPDec/include/tp_data.h +++ b/libMpegTPDec/include/tp_data.h @@ -367,7 +367,8 @@ typedef INT (*cbFreeMem_t)(void *, const CSAudioSpecificConfig *); typedef INT (*cbCtrlCFGChange_t)(void *, const CCtrlCFGChange *); typedef INT (*cbSsc_t)(void *, HANDLE_FDK_BITSTREAM, const AUDIO_OBJECT_TYPE coreCodec, - const INT samplingRate, const INT stereoConfigIndex, + const INT samplingRate, const INT frameSize, + const INT stereoConfigIndex, const INT coreSbrFrameLengthIndex, const INT configBytes, const UCHAR configMode, UCHAR *configChanged); diff --git a/libMpegTPDec/src/tpdec_asc.cpp b/libMpegTPDec/src/tpdec_asc.cpp index 5270f2b..28bc22d 100644 --- a/libMpegTPDec/src/tpdec_asc.cpp +++ b/libMpegTPDec/src/tpdec_asc.cpp @@ -1413,7 +1413,9 @@ static TRANSPORTDEC_ERROR EldSpecificConfig_Parse(CSAudioSpecificConfig *asc, esc->m_useLdQmfTimeAlign = 1; if (cb->cbSsc != NULL) { ErrorStatus = (TRANSPORTDEC_ERROR)cb->cbSsc( - cb->cbSscData, hBs, asc->m_aot, asc->m_extensionSamplingFrequency, + cb->cbSscData, hBs, asc->m_aot, + asc->m_samplingFrequency << esc->m_sbrSamplingRate, + asc->m_samplesPerFrame << esc->m_sbrSamplingRate, 1, /* stereoConfigIndex */ -1, /* nTimeSlots: read from bitstream */ eldExtLen, asc->configMode, &asc->SacConfigChanged); @@ -1812,9 +1814,16 @@ static TRANSPORTDEC_ERROR UsacRsv60DecoderConfig_Parse( if (usc->element[i].m_stereoConfigIndex > 0) { if (cb->cbSsc != NULL) { + int samplesPerFrame = asc->m_samplesPerFrame; + + if (usc->m_sbrRatioIndex == 1) samplesPerFrame <<= 2; + if (usc->m_sbrRatioIndex == 2) + samplesPerFrame = (samplesPerFrame * 8) / 3; + if (usc->m_sbrRatioIndex == 3) samplesPerFrame <<= 1; + /* Mps212Config() ISO/IEC FDIS 23003-3 */ if (cb->cbSsc(cb->cbSscData, hBs, asc->m_aot, - asc->m_extensionSamplingFrequency, + asc->m_extensionSamplingFrequency, samplesPerFrame, usc->element[i].m_stereoConfigIndex, usc->m_coreSbrFrameLengthIndex, 0, /* don't know the length */ @@ -2181,8 +2190,9 @@ TRANSPORTDEC_ERROR AudioSpecificConfig_Parse( case AOT_MPEGS: if (cb->cbSsc != NULL) { if (cb->cbSsc(cb->cbSscData, bs, self->m_aot, self->m_samplingFrequency, - 1, -1, /* nTimeSlots: read from bitstream */ - 0, /* don't know the length */ + self->m_samplesPerFrame, 1, + -1, /* nTimeSlots: read from bitstream */ + 0, /* don't know the length */ self->configMode, &self->SacConfigChanged)) { return TRANSPORTDEC_UNSUPPORTED_FORMAT; } @@ -2365,10 +2375,17 @@ static TRANSPORTDEC_ERROR Drm_xHEAACDecoderConfig( /*usc->element[elemIdx].m_stereoConfigIndex =*/FDKreadBits(hBs, 2); if (usc->element[elemIdx].m_stereoConfigIndex > 0) { if (cb->cbSsc != NULL) { + int samplesPerFrame = asc->m_samplesPerFrame; + + if (usc->m_sbrRatioIndex == 1) samplesPerFrame <<= 2; + if (usc->m_sbrRatioIndex == 2) + samplesPerFrame = (samplesPerFrame * 8) / 3; + if (usc->m_sbrRatioIndex == 3) samplesPerFrame <<= 1; + ErrorStatus = (TRANSPORTDEC_ERROR)cb->cbSsc( cb->cbSscData, hBs, AOT_DRM_USAC, /* syntax differs from MPEG Mps212Config() */ - asc->m_extensionSamplingFrequency, + asc->m_extensionSamplingFrequency, samplesPerFrame, usc->element[elemIdx].m_stereoConfigIndex, usc->m_coreSbrFrameLengthIndex, 0, /* don't know the length */ asc->configMode, &asc->SacConfigChanged); diff --git a/libMpegTPEnc/include/tp_data.h b/libMpegTPEnc/include/tp_data.h index 6f032d1..00de356 100644 --- a/libMpegTPEnc/include/tp_data.h +++ b/libMpegTPEnc/include/tp_data.h @@ -367,7 +367,8 @@ typedef INT (*cbFreeMem_t)(void *, const CSAudioSpecificConfig *); typedef INT (*cbCtrlCFGChange_t)(void *, const CCtrlCFGChange *); typedef INT (*cbSsc_t)(void *, HANDLE_FDK_BITSTREAM, const AUDIO_OBJECT_TYPE coreCodec, - const INT samplingRate, const INT stereoConfigIndex, + const INT samplingRate, const INT frameSize, + const INT stereoConfigIndex, const INT coreSbrFrameLengthIndex, const INT configBytes, const UCHAR configMode, UCHAR *configChanged); diff --git a/libMpegTPEnc/src/tpenc_asc.cpp b/libMpegTPEnc/src/tpenc_asc.cpp index ce4e364..0b484a0 100644 --- a/libMpegTPEnc/src/tpenc_asc.cpp +++ b/libMpegTPEnc/src/tpenc_asc.cpp @@ -795,7 +795,7 @@ static int transportEnc_writeELDSpecificConfig(HANDLE_FDK_BITSTREAM hBs, const INT eldExtLen = (cb->cbSsc(cb->cbSscData, NULL, config->aot, config->extSamplingRate, 0, - 0, 0, 0, NULL) + + 0, 0, 0, 0, NULL) + 7) >> 3; INT cnt = eldExtLen; @@ -818,7 +818,7 @@ static int transportEnc_writeELDSpecificConfig(HANDLE_FDK_BITSTREAM hBs, } cb->cbSsc(cb->cbSscData, hBs, config->aot, config->extSamplingRate, 0, 0, 0, - 0, NULL); + 0, 0, NULL); } if (config->downscaleSamplingRate != 0 && diff --git a/libSACdec/include/sac_dec_lib.h b/libSACdec/include/sac_dec_lib.h index 2797a10..9913279 100644 --- a/libSACdec/include/sac_dec_lib.h +++ b/libSACdec/include/sac_dec_lib.h @@ -315,9 +315,9 @@ SACDEC_ERROR mpegSurroundDecoder_Init( */ SACDEC_ERROR mpegSurroundDecoder_Config( CMpegSurroundDecoder *pMpegSurroundDecoder, HANDLE_FDK_BITSTREAM hBs, - AUDIO_OBJECT_TYPE coreCodec, INT samplingRate, INT stereoConfigIndex, - INT coreSbrFrameLengthIndex, INT configBytes, const UCHAR configMode, - UCHAR *configChanged); + AUDIO_OBJECT_TYPE coreCodec, INT samplingRate, INT frameSize, + INT stereoConfigIndex, INT coreSbrFrameLengthIndex, INT configBytes, + const UCHAR configMode, UCHAR *configChanged); SACDEC_ERROR mpegSurroundDecoder_ConfigureQmfDomain( diff --git a/libSACdec/src/sac_bitdec.cpp b/libSACdec/src/sac_bitdec.cpp index 1049c3d..883e1e8 100644 --- a/libSACdec/src/sac_bitdec.cpp +++ b/libSACdec/src/sac_bitdec.cpp @@ -517,6 +517,10 @@ SACDEC_ERROR SpatialDecParseSpecificConfig( pSpatialSpecificConfig->tempShapeConfig = (SPATIALDEC_TS_CONF)FDKreadBits(bitstream, 2); + if (pSpatialSpecificConfig->tempShapeConfig > 2) { + return MPS_PARSE_ERROR; /* reserved value */ + } + pSpatialSpecificConfig->decorrConfig = (SPATIALDEC_DECORR_CONF)FDKreadBits(bitstream, 2); if (pSpatialSpecificConfig->decorrConfig > 2) { diff --git a/libSACdec/src/sac_dec_lib.cpp b/libSACdec/src/sac_dec_lib.cpp index 7549e51..5792858 100644 --- a/libSACdec/src/sac_dec_lib.cpp +++ b/libSACdec/src/sac_dec_lib.cpp @@ -237,6 +237,11 @@ struct MpegSurroundDecoder { SPATIAL_DEC_CONFIG decConfig; }; +SACDEC_ERROR +static sscCheckOutOfBand(const SPATIAL_SPECIFIC_CONFIG *pSsc, + const INT coreCodec, const INT sampleRate, + const INT frameSize); + static SACDEC_ERROR sscParseCheck(const SPATIAL_SPECIFIC_CONFIG *pSsc); /** @@ -694,11 +699,13 @@ bail: **/ SACDEC_ERROR mpegSurroundDecoder_Config( CMpegSurroundDecoder *pMpegSurroundDecoder, HANDLE_FDK_BITSTREAM hBs, - AUDIO_OBJECT_TYPE coreCodec, INT samplingRate, INT stereoConfigIndex, - INT coreSbrFrameLengthIndex, INT configBytes, const UCHAR configMode, - UCHAR *configChanged) { + AUDIO_OBJECT_TYPE coreCodec, INT samplingRate, INT frameSize, + INT stereoConfigIndex, INT coreSbrFrameLengthIndex, INT configBytes, + const UCHAR configMode, UCHAR *configChanged) { SACDEC_ERROR err = MPS_OK; SPATIAL_SPECIFIC_CONFIG spatialSpecificConfig; + SPATIAL_SPECIFIC_CONFIG *pSsc = + &pMpegSurroundDecoder->spatialSpecificConfigBackup; switch (coreCodec) { case AOT_DRM_USAC: @@ -709,6 +716,7 @@ SACDEC_ERROR mpegSurroundDecoder_Config( err = SpatialDecParseMps212Config( hBs, &spatialSpecificConfig, samplingRate, coreCodec, stereoConfigIndex, coreSbrFrameLengthIndex); + pSsc = &spatialSpecificConfig; } else { err = SpatialDecParseMps212Config( hBs, &pMpegSurroundDecoder->spatialSpecificConfigBackup, @@ -723,6 +731,7 @@ SACDEC_ERROR mpegSurroundDecoder_Config( * into temporarily allocated structure */ err = SpatialDecParseSpecificConfig(hBs, &spatialSpecificConfig, configBytes, coreCodec); + pSsc = &spatialSpecificConfig; } else { err = SpatialDecParseSpecificConfig( hBs, &pMpegSurroundDecoder->spatialSpecificConfigBackup, @@ -738,14 +747,21 @@ SACDEC_ERROR mpegSurroundDecoder_Config( goto bail; } + err = sscCheckOutOfBand(pSsc, coreCodec, samplingRate, frameSize); + + if (err != MPS_OK) { + goto bail; + } + if (configMode & AC_CM_DET_CFG_CHANGE) { return err; } if (configMode & AC_CM_ALLOC_MEM) { if (*configChanged) { - if ((err = mpegSurroundDecoder_Open(&pMpegSurroundDecoder, - stereoConfigIndex, NULL))) { + err = mpegSurroundDecoder_Open(&pMpegSurroundDecoder, stereoConfigIndex, + NULL); + if (err) { return err; } } @@ -815,29 +831,9 @@ static MPEGS_OPMODE mpegSurroundOperationMode( * \return MPS_OK on sucess, and else on parse error. */ static SACDEC_ERROR sscParseCheck(const SPATIAL_SPECIFIC_CONFIG *pSsc) { - SACDEC_ERROR err = MPS_OK; - if (pSsc->samplingFreq > 96000) return MPS_PARSE_ERROR; if (pSsc->samplingFreq < 8000) return MPS_PARSE_ERROR; - switch (pSsc->freqRes) { - case SPATIALDEC_FREQ_RES_28: - case SPATIALDEC_FREQ_RES_20: - case SPATIALDEC_FREQ_RES_14: - case SPATIALDEC_FREQ_RES_10: - case SPATIALDEC_FREQ_RES_23: - case SPATIALDEC_FREQ_RES_15: - case SPATIALDEC_FREQ_RES_12: - case SPATIALDEC_FREQ_RES_9: - case SPATIALDEC_FREQ_RES_7: - case SPATIALDEC_FREQ_RES_5: - case SPATIALDEC_FREQ_RES_4: - break; - case SPATIALDEC_FREQ_RES_40: /* 40 doesn't exist in ISO/IEC 23003-1 */ - default: - return MPS_PARSE_ERROR; - } - if ((pSsc->treeConfig < 0) || (pSsc->treeConfig > 7)) { return MPS_PARSE_ERROR; } @@ -846,17 +842,9 @@ static SACDEC_ERROR sscParseCheck(const SPATIAL_SPECIFIC_CONFIG *pSsc) { return MPS_PARSE_ERROR; } - if (pSsc->tempShapeConfig == 3) { - return MPS_PARSE_ERROR; - } - - if (pSsc->decorrConfig == 3) { - return MPS_PARSE_ERROR; - } - /* now we are sure there were no parsing errors */ - return err; + return MPS_OK; } /** @@ -1024,6 +1012,11 @@ static SACDEC_ERROR sscCheckInBand(SPATIAL_SPECIFIC_CONFIG *pSsc, FDK_ASSERT(pSsc != NULL); + /* check ssc for parse errors */ + if (sscParseCheck(pSsc) != MPS_OK) { + err = MPS_PARSE_ERROR; + } + /* core fs and mps fs must match */ if (pSsc->samplingFreq != sampleRate) { err = MPS_PARSE_ERROR /* MPEGSDEC_SSC_PARSE_ERROR */; @@ -1093,6 +1086,83 @@ mpegSurroundDecoder_ConfigureQmfDomain( return err; } +/** + * \brief Check out-of-band config + * + * \param pSsc spatial specific config handle. + * \param coreCodec core codec. + * \param sampleRate sampling frequency. + * + * \return errorStatus + */ +SACDEC_ERROR +sscCheckOutOfBand(const SPATIAL_SPECIFIC_CONFIG *pSsc, const INT coreCodec, + const INT sampleRate, const INT frameSize) { + FDK_ASSERT(pSsc != NULL); + int qmfBands = 0; + + /* check ssc for parse errors */ + if (sscParseCheck(pSsc) != MPS_OK) { + return MPS_PARSE_ERROR; + } + + switch (coreCodec) { + case AOT_USAC: + case AOT_DRM_USAC: + /* ISO/IEC 23003-1:2007(E), Chapter 6.3.3, Support for lower and higher + * sampling frequencies */ + if (pSsc->samplingFreq >= 55426) { + return MPS_PARSE_ERROR; + } + break; + case AOT_ER_AAC_LD: + case AOT_ER_AAC_ELD: + /* core fs and mps fs must match */ + if (pSsc->samplingFreq != sampleRate) { + return MPS_PARSE_ERROR; + } + + /* ISO/IEC 14496-3:2009 FDAM 3: Chapter 1.5.2.3, Levels for the Low Delay + * AAC v2 profile */ + if (pSsc->samplingFreq > 48000) { + return MPS_PARSE_ERROR; + } + + qmfBands = mpegSurroundDecoder_GetNrOfQmfBands(pSsc, pSsc->samplingFreq); + switch (frameSize) { + case 480: + if (!((qmfBands == 32) && (pSsc->nTimeSlots == 15))) { + return MPS_PARSE_ERROR; + } + break; + case 960: + if (!((qmfBands == 64) && (pSsc->nTimeSlots == 15))) { + return MPS_PARSE_ERROR; + } + break; + case 512: + if (!(((qmfBands == 32) && (pSsc->nTimeSlots == 16)) || + ((qmfBands == 64) && (pSsc->nTimeSlots == 8)))) { + return MPS_PARSE_ERROR; + } + break; + case 1024: + if (!((qmfBands == 64) && (pSsc->nTimeSlots == 16))) { + return MPS_PARSE_ERROR; + } + break; + default: + return MPS_PARSE_ERROR; + } + break; + default: + return MPS_PARSE_ERROR; + break; + } + + return MPS_OK; +} + /** * \brief Decode MPEG Surround frame. **/ -- cgit v1.2.3