History

Stability fixes

menno committed 22 years ago

Commit dcebb7e1 parent 394d1b717 files · +287 −117Browse files

Showing the changes to libfaad/decoder.c (1 of 17 files). Show all

Unified · Split

libfaad/decoder.c+30−6
@@ -22,7 +22,7 @@ · 21 unmodified lines
2222 ** Commercial non-GPL licensing of this software is possible.
2323 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
2424 **
25−** $Id: decoder.c,v 1.91 2004/01/14 20:32:30 menno Exp $
25+** $Id: decoder.c,v 1.92 2004/01/16 20:20:32 menno Exp $
2626 **/
2727
2828 #include "common.h"
@@ -128,7 +128,7 @@ faacDecHandle FAADAPI faacDecOpen(void) · 99 unmodified lines
128128 }
129129
130130 #ifdef SBR_DEC
131− for (i = 0; i < 32; i++)
131+ for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++)
132132 {
133133 hDecoder->sbr[i] = NULL;
134134 }
@@ -441,7 +441,7 @@ int8_t FAADAPI faacDecInitDRM(faacDecHandle hDecoder, uint32_t samplerate, · 306 unmodified lines
441441 }
442442
443443 #ifdef SBR_DEC
444− for (i = 0; i < 32; i++)
444+ for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++)
445445 {
446446 if (hDecoder->sbr[i])
447447 sbrDecodeEnd(hDecoder->sbr[i]);
@@ -497,7 +497,7 @@ void FAADAPI faacDecClose(faacDecHandle hDecoder) · 49 unmodified lines
497497 if (hDecoder->sample_buffer) faad_free(hDecoder->sample_buffer);
498498
499499 #ifdef SBR_DEC
500− for (i = 0; i < 32; i++)
500+ for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++)
501501 {
502502 if (hDecoder->sbr[i])
503503 sbrDecodeEnd(hDecoder->sbr[i]);
@@ -803,6 +803,13 @@ void* FAADAPI faacDecDecode(faacDecHandle hDecoder, · 299 unmodified lines
803803 if (hInfo->error > 0)
804804 goto error;
805805
806+ /* safety check */
807+ if (channels == 0 || channels > MAX_CHANNELS)
808+ {
809+ /* invalid number of channels */
810+ hInfo->error = 12;
811+ goto error;
812+ }
806813
807814 /* no more bit reading after this */
808815 bitsconsumed = faad_get_processed_bits(&ld);
@@ -862,7 +869,8 @@ void* FAADAPI faacDecDecode(faacDecHandle hDecoder, · 53 unmodified lines
862869 }
863870
864871 /* allocate the buffer for the final samples */
865− if (hDecoder->sample_buffer == NULL)
872+ if ((hDecoder->sample_buffer == NULL) ||
873+ (hDecoder->alloced_channels != output_channels))
866874 {
867875 static const uint8_t str[] = { sizeof(int16_t), sizeof(int32_t), sizeof(int32_t),
868876 sizeof(float32_t), sizeof(double), sizeof(int16_t), sizeof(int16_t),
@@ -873,7 +881,11 @@ void* FAADAPI faacDecDecode(faacDecHandle hDecoder, · 4 unmodified lines
873881 if ((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1))
874882 stride = 2 * stride;
875883 #endif
876− hDecoder->sample_buffer = faad_malloc(frame_len*channels*stride);
884+ if (hDecoder->sample_buffer)
885+ faad_free(hDecoder->sample_buffer);
886+ hDecoder->sample_buffer = NULL;
887+ hDecoder->sample_buffer = faad_malloc(frame_len*output_channels*stride);
888+ hDecoder->alloced_channels = output_channels;
877889 }
878890
879891 sample_buffer = hDecoder->sample_buffer;
@@ -881,11 +893,23 @@ void* FAADAPI faacDecDecode(faacDecHandle hDecoder, · 1 unmodified line
881893 #ifdef SBR_DEC
882894 if ((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1))
883895 {
896+ uint8_t ele;
897+
884898 /* this data is different when SBR is used or when the data is upsampled */
885899 frame_len *= 2;
886900 hInfo->samples *= 2;
887901 hInfo->samplerate *= 2;
888902
903+ /* check if every element was provided with SBR data */
904+ for (ele = 0; ele < hDecoder->fr_ch_ele; ele++)
905+ {
906+ if (hDecoder->sbr[ele] == NULL)
907+ {
908+ hInfo->error = 25;
909+ goto error;
910+ }
911+ }
912+
889913 /* sbr */
890914 if (hDecoder->sbr_present_flag == 1)
891915 {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t