diff options
author | Fraunhofer IIS FDK <audio-fdk@iis.fraunhofer.de> | 2018-06-08 18:03:16 +0200 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2018-09-10 23:19:19 +0000 |
commit | 9744e41c40598c6a0b74440f3b5be63f9f3708a5 (patch) | |
tree | 66fe1fc4eb2c283bcebf91e53f365c6b22f1b47c /libFDK | |
parent | 61381bd0f4bc012876ccf4b63eafddd2d60c35c9 (diff) | |
download | fdk-aac-9744e41c40598c6a0b74440f3b5be63f9f3708a5.tar.gz fdk-aac-9744e41c40598c6a0b74440f3b5be63f9f3708a5.tar.bz2 fdk-aac-9744e41c40598c6a0b74440f3b5be63f9f3708a5.zip |
Prevent bit buffer counter overflow.
While long-term test we discovered a bit counter overflow in the bit buffer.
The bit buffer state was only used by HCR and RVLC tool and can easily be substituted with FDKgetValidBits() call.
The following patch completely removes the bit counter and all its obsolete functions.
Bug: 112662184
Test: atest DecoderTestXheAac ; atest DecoderTestAacDrc
Change-Id: Icee0519d26a2aa62367d2dece59cd3d60ffcade7
(cherry picked from commit 15292f7e9620caf9e8df26a62efc2a2891ea822e)
Diffstat (limited to 'libFDK')
-rw-r--r-- | libFDK/include/FDK_bitbuffer.h | 6 | ||||
-rw-r--r-- | libFDK/include/FDK_bitstream.h | 46 | ||||
-rw-r--r-- | libFDK/src/FDK_bitbuffer.cpp | 29 |
3 files changed, 0 insertions, 81 deletions
diff --git a/libFDK/include/FDK_bitbuffer.h b/libFDK/include/FDK_bitbuffer.h index ed0b2f6..19a24b3 100644 --- a/libFDK/include/FDK_bitbuffer.h +++ b/libFDK/include/FDK_bitbuffer.h @@ -113,7 +113,6 @@ typedef struct { UINT ValidBits; UINT ReadOffset; UINT WriteOffset; - UINT BitCnt; UINT BitNdx; UCHAR *Buffer; @@ -159,15 +158,10 @@ void FDK_pushBack(HANDLE_FDK_BITBUF hBitBuffer, const UINT numberOfBits, void FDK_pushForward(HANDLE_FDK_BITBUF hBitBuffer, const UINT numberOfBits, UCHAR config); -void FDK_byteAlign(HANDLE_FDK_BITBUF hBitBuffer, UCHAR config); - UINT FDK_getValidBits(HANDLE_FDK_BITBUF hBitBuffer); INT FDK_getFreeBits(HANDLE_FDK_BITBUF hBitBuffer); -void FDK_setBitCnt(HANDLE_FDK_BITBUF hBitBuffer, const UINT value); -INT FDK_getBitCnt(HANDLE_FDK_BITBUF hBitBuffer); - void FDK_Feed(HANDLE_FDK_BITBUF hBitBuffer, const UCHAR inputBuffer[], const UINT bufferSize, UINT *bytesValid); diff --git a/libFDK/include/FDK_bitstream.h b/libFDK/include/FDK_bitstream.h index 49eeeaf..f799026 100644 --- a/libFDK/include/FDK_bitstream.h +++ b/libFDK/include/FDK_bitstream.h @@ -481,21 +481,6 @@ FDK_INLINE void FDKsyncCacheBwd(HANDLE_FDK_BITSTREAM hBitStream) { } /** - * \brief Byte Alignment Function. - * This function performs the byte_alignment() syntactic function on the - * input stream, i.e. some bits will be discarded/padded so that the next bits - * to be read/written will be aligned on a byte boundary with respect to - * the bit position 0. - * - * \param hBitStream HANDLE_FDK_BITSTREAM handle - * \return void - */ -FDK_INLINE void FDKbyteAlign(HANDLE_FDK_BITSTREAM hBitStream) { - FDKsyncCache(hBitStream); - FDK_byteAlign(&hBitStream->hBitBuf, (UCHAR)hBitStream->ConfigCache); -} - -/** * \brief Byte Alignment Function with anchor * This function performs the byte_alignment() syntactic function on the * input stream, i.e. some bits will be discarded so that the next bits to be @@ -604,37 +589,6 @@ FDK_INLINE INT FDKgetFreeBits(HANDLE_FDK_BITSTREAM hBitStream) { } /** - * \brief reset bitcounter in bitBuffer to zero. - * \param hBitStream HANDLE_FDK_BITSTREAM handle - * \return void - */ -FDK_INLINE void FDKresetBitCnt(HANDLE_FDK_BITSTREAM hBitStream) { - FDKsyncCache(hBitStream); - FDK_setBitCnt(&hBitStream->hBitBuf, 0); -} - -/** - * \brief set bitcoutner in bitBuffer to given value. - * \param hBitStream HANDLE_FDK_BITSTREAM handle - * \param value new value to be assigned to the bit counter - * \return void - */ -FDK_INLINE void FDKsetBitCnt(HANDLE_FDK_BITSTREAM hBitStream, UINT value) { - FDKsyncCache(hBitStream); - FDK_setBitCnt(&hBitStream->hBitBuf, value); -} - -/** - * \brief get bitcounter state from bitBuffer. - * \param hBitStream HANDLE_FDK_BITSTREAM handle - * \return current bit counter value - */ -FDK_INLINE INT FDKgetBitCnt(HANDLE_FDK_BITSTREAM hBitStream) { - FDKsyncCache(hBitStream); - return FDK_getBitCnt(&hBitStream->hBitBuf); -} - -/** * \brief Fill the BitBuffer with a number of input bytes from external source. * The bytesValid variable returns the number of ramaining valid bytes in * extern inputBuffer. diff --git a/libFDK/src/FDK_bitbuffer.cpp b/libFDK/src/FDK_bitbuffer.cpp index a990c58..98905ea 100644 --- a/libFDK/src/FDK_bitbuffer.cpp +++ b/libFDK/src/FDK_bitbuffer.cpp @@ -128,7 +128,6 @@ void FDK_InitBitBuffer(HANDLE_FDK_BITBUF hBitBuf, UCHAR *pBuffer, UINT bufSize, hBitBuf->ValidBits = validBits; hBitBuf->ReadOffset = 0; hBitBuf->WriteOffset = 0; - hBitBuf->BitCnt = 0; hBitBuf->BitNdx = 0; hBitBuf->Buffer = pBuffer; @@ -151,7 +150,6 @@ void FDK_ResetBitBuffer(HANDLE_FDK_BITBUF hBitBuf) { hBitBuf->ValidBits = 0; hBitBuf->ReadOffset = 0; hBitBuf->WriteOffset = 0; - hBitBuf->BitCnt = 0; hBitBuf->BitNdx = 0; } @@ -161,7 +159,6 @@ INT FDK_get(HANDLE_FDK_BITBUF hBitBuf, const UINT numberOfBits) { UINT bitOffset = hBitBuf->BitNdx & 0x07; hBitBuf->BitNdx = (hBitBuf->BitNdx + numberOfBits) & (hBitBuf->bufBits - 1); - hBitBuf->BitCnt += numberOfBits; hBitBuf->ValidBits -= numberOfBits; UINT byteMask = hBitBuf->bufSize - 1; @@ -184,7 +181,6 @@ INT FDK_get(HANDLE_FDK_BITBUF hBitBuf, const UINT numberOfBits) { INT FDK_get32(HANDLE_FDK_BITBUF hBitBuf) { UINT BitNdx = hBitBuf->BitNdx + 32; hBitBuf->BitNdx = BitNdx & (hBitBuf->bufBits - 1); - hBitBuf->BitCnt += 32; hBitBuf->ValidBits = (UINT)((INT)hBitBuf->ValidBits - (INT)32); UINT byteOffset = (BitNdx - 1) >> 3; @@ -223,7 +219,6 @@ INT FDK_getBwd(HANDLE_FDK_BITBUF hBitBuf, const UINT numberOfBits) { int i; hBitBuf->BitNdx = (hBitBuf->BitNdx - numberOfBits) & (hBitBuf->bufBits - 1); - hBitBuf->BitCnt -= numberOfBits; hBitBuf->ValidBits += numberOfBits; UINT tx = hBitBuf->Buffer[(byteOffset - 3) & byteMask] << 24 | @@ -256,7 +251,6 @@ void FDK_put(HANDLE_FDK_BITBUF hBitBuf, UINT value, const UINT numberOfBits) { UINT bitOffset = hBitBuf->BitNdx & 0x7; hBitBuf->BitNdx = (hBitBuf->BitNdx + numberOfBits) & (hBitBuf->bufBits - 1); - hBitBuf->BitCnt += numberOfBits; hBitBuf->ValidBits += numberOfBits; UINT byteMask = hBitBuf->bufSize - 1; @@ -307,7 +301,6 @@ void FDK_putBwd(HANDLE_FDK_BITBUF hBitBuf, UINT value, int i; hBitBuf->BitNdx = (hBitBuf->BitNdx - numberOfBits) & (hBitBuf->bufBits - 1); - hBitBuf->BitCnt -= numberOfBits; hBitBuf->ValidBits -= numberOfBits; /* in place turn around */ @@ -344,7 +337,6 @@ void FDK_putBwd(HANDLE_FDK_BITBUF hBitBuf, UINT value, #ifndef FUNCTION_FDK_pushBack void FDK_pushBack(HANDLE_FDK_BITBUF hBitBuf, const UINT numberOfBits, UCHAR config) { - hBitBuf->BitCnt = (UINT)((INT)hBitBuf->BitCnt - (INT)numberOfBits); hBitBuf->ValidBits = (config == 0) ? (UINT)((INT)hBitBuf->ValidBits + (INT)numberOfBits) : ((UINT)((INT)hBitBuf->ValidBits - (INT)numberOfBits)); @@ -355,7 +347,6 @@ void FDK_pushBack(HANDLE_FDK_BITBUF hBitBuf, const UINT numberOfBits, void FDK_pushForward(HANDLE_FDK_BITBUF hBitBuf, const UINT numberOfBits, UCHAR config) { - hBitBuf->BitCnt = (UINT)((INT)hBitBuf->BitCnt + (INT)numberOfBits); hBitBuf->ValidBits = (config == 0) ? ((UINT)((INT)hBitBuf->ValidBits - (INT)numberOfBits)) : (UINT)((INT)hBitBuf->ValidBits + (INT)numberOfBits); @@ -363,19 +354,6 @@ void FDK_pushForward(HANDLE_FDK_BITBUF hBitBuf, const UINT numberOfBits, (UINT)((INT)hBitBuf->BitNdx + (INT)numberOfBits) & (hBitBuf->bufBits - 1); } -void FDK_byteAlign(HANDLE_FDK_BITBUF hBitBuf, UCHAR config) { - INT alignment = hBitBuf->BitCnt & 0x07; - - if (alignment) { - if (config == 0) - FDK_pushForward(hBitBuf, 8 - alignment, config); /* BS_READER */ - else - FDK_put(hBitBuf, 0, 8 - alignment); /* BS_WRITER */ - } - - hBitBuf->BitCnt = 0; -} - #ifndef FUNCTION_FDK_getValidBits UINT FDK_getValidBits(HANDLE_FDK_BITBUF hBitBuf) { return hBitBuf->ValidBits; } #endif /* #ifndef FUNCTION_FDK_getValidBits */ @@ -384,12 +362,6 @@ INT FDK_getFreeBits(HANDLE_FDK_BITBUF hBitBuf) { return (hBitBuf->bufBits - hBitBuf->ValidBits); } -void FDK_setBitCnt(HANDLE_FDK_BITBUF hBitBuf, const UINT value) { - hBitBuf->BitCnt = value; -} - -INT FDK_getBitCnt(HANDLE_FDK_BITBUF hBitBuf) { return hBitBuf->BitCnt; } - void FDK_Feed(HANDLE_FDK_BITBUF hBitBuf, const UCHAR *RESTRICT inputBuffer, const UINT bufferSize, UINT *bytesValid) { inputBuffer = &inputBuffer[bufferSize - *bytesValid]; @@ -438,7 +410,6 @@ void CopyAlignedBlock(HANDLE_FDK_BITBUF h_BitBufSrc, UCHAR *RESTRICT dstBuffer, h_BitBufSrc->BitNdx = (h_BitBufSrc->BitNdx + bToRead) & (h_BitBufSrc->bufBits - 1); - h_BitBufSrc->BitCnt += bToRead; h_BitBufSrc->ValidBits -= bToRead; } |