ref: ada4482ffa42204d7ad7b4f62e8c2adfc2095d5a
parent: c0c56a7b0559f23b4b7b68e9bb5f449907e750c0
author: Krzysztof Nikiel <knik@users.sourceforge.net>
date: Sat Sep 2 14:38:00 EDT 2017
frame buffer overrun check
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,6 @@
-1.29.7.3
+ * allowed even higher bitrates, including ADTS
+ * removed broken object types: Main and LTP
* some mp4 atoms fixed for better compalibility
-1.29.7.2
* stdin seek bug fixed
1.29.7
* quantizer tweaked to better support high bitrates
--- a/libfaac/bitstream.c
+++ b/libfaac/bitstream.c
@@ -152,7 +152,8 @@
int bits = 0;
int bitsLeftAfterFill, numFillBits;
- CountBitstream(hEncoder, coderInfo, channelInfo, bitStream, numChannel);
+ if (CountBitstream(hEncoder, coderInfo, channelInfo, bitStream, numChannel) < 0)
+ return -1;
if(hEncoder->config.outputFormat == 1){
bits += WriteADTSHeader(hEncoder, bitStream, 1);
@@ -315,6 +316,11 @@
bits += ByteAlign(bitStream, 0, bits);
hEncoder->usedBytes = bit2byte(bits);
+ if (hEncoder->usedBytes >= ADTS_FRAMESIZE)
+ {
+ fprintf(stderr, "frame buffer overrun\n");
+ return -1;
+ }
return bits;
}
--- a/libfaac/bitstream.h
+++ b/libfaac/bitstream.h
@@ -137,6 +137,7 @@
#define LONG_NUMBIT 32 /* bits in unsigned long */
#define bit2byte(a) (((a)+BYTE_NUMBIT-1)/BYTE_NUMBIT)
+enum {ADTS_FRAMESIZE = 1 << 13};
typedef struct
{
--- a/libfaac/frame.c
+++ b/libfaac/frame.c
@@ -284,7 +284,7 @@
return NULL;
*inputSamples = FRAME_LEN*numChannels;
- *maxOutputBytes = 0x2000;
+ *maxOutputBytes = ADTS_FRAMESIZE;
#ifdef DRM
*maxOutputBytes += 1; /* for CRC */
@@ -718,7 +718,8 @@
/* Write the AAC bitstream */
bitStream = OpenBitStream(bufferSize, outputBuffer);
- WriteBitstream(hEncoder, coderInfo, channelInfo, bitStream, numChannels);
+ if (WriteBitstream(hEncoder, coderInfo, channelInfo, bitStream, numChannels) < 0)
+ return -1;
/* Close the bitstream and return the number of bytes written */
frameBytes = CloseBitStream(bitStream);