Showing the changes to libfaad/decoder.c (1 of 17 files). Show all
Unified · Split
| @@ -22,7 +22,7 @@ · 21 unmodified lines | ||
| 22 | 22 | ** Commercial non-GPL licensing of this software is possible. |
| 23 | 23 | ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com. |
| 24 | 24 | ** |
| 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 $ | |
| 26 | 26 | **/ |
| 27 | 27 | |
| 28 | 28 | #include "common.h" |
| @@ -128,7 +128,7 @@ faacDecHandle FAADAPI faacDecOpen(void) · 99 unmodified lines | ||
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | #ifdef SBR_DEC |
| 131 | − for (i = 0; i < 32; i++) | |
| 131 | + for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++) | |
| 132 | 132 | { |
| 133 | 133 | hDecoder->sbr[i] = NULL; |
| 134 | 134 | } |
| @@ -441,7 +441,7 @@ int8_t FAADAPI faacDecInitDRM(faacDecHandle hDecoder, uint32_t samplerate, · 306 unmodified lines | ||
| 441 | 441 | } |
| 442 | 442 | |
| 443 | 443 | #ifdef SBR_DEC |
| 444 | − for (i = 0; i < 32; i++) | |
| 444 | + for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++) | |
| 445 | 445 | { |
| 446 | 446 | if (hDecoder->sbr[i]) |
| 447 | 447 | sbrDecodeEnd(hDecoder->sbr[i]); |
| @@ -497,7 +497,7 @@ void FAADAPI faacDecClose(faacDecHandle hDecoder) · 49 unmodified lines | ||
| 497 | 497 | if (hDecoder->sample_buffer) faad_free(hDecoder->sample_buffer); |
| 498 | 498 | |
| 499 | 499 | #ifdef SBR_DEC |
| 500 | − for (i = 0; i < 32; i++) | |
| 500 | + for (i = 0; i < MAX_SYNTAX_ELEMENTS; i++) | |
| 501 | 501 | { |
| 502 | 502 | if (hDecoder->sbr[i]) |
| 503 | 503 | sbrDecodeEnd(hDecoder->sbr[i]); |
| @@ -803,6 +803,13 @@ void* FAADAPI faacDecDecode(faacDecHandle hDecoder, · 299 unmodified lines | ||
| 803 | 803 | if (hInfo->error > 0) |
| 804 | 804 | goto error; |
| 805 | 805 | |
| 806 | + /* safety check */ | |
| 807 | + if (channels == 0 || channels > MAX_CHANNELS) | |
| 808 | + { | |
| 809 | + /* invalid number of channels */ | |
| 810 | + hInfo->error = 12; | |
| 811 | + goto error; | |
| 812 | + } | |
| 806 | 813 | |
| 807 | 814 | /* no more bit reading after this */ |
| 808 | 815 | bitsconsumed = faad_get_processed_bits(&ld); |
| @@ -862,7 +869,8 @@ void* FAADAPI faacDecDecode(faacDecHandle hDecoder, · 53 unmodified lines | ||
| 862 | 869 | } |
| 863 | 870 | |
| 864 | 871 | /* 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)) | |
| 866 | 874 | { |
| 867 | 875 | static const uint8_t str[] = { sizeof(int16_t), sizeof(int32_t), sizeof(int32_t), |
| 868 | 876 | sizeof(float32_t), sizeof(double), sizeof(int16_t), sizeof(int16_t), |
| @@ -873,7 +881,11 @@ void* FAADAPI faacDecDecode(faacDecHandle hDecoder, · 4 unmodified lines | ||
| 873 | 881 | if ((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1)) |
| 874 | 882 | stride = 2 * stride; |
| 875 | 883 | #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; | |
| 877 | 889 | } |
| 878 | 890 | |
| 879 | 891 | sample_buffer = hDecoder->sample_buffer; |
| @@ -881,11 +893,23 @@ void* FAADAPI faacDecDecode(faacDecHandle hDecoder, · 1 unmodified line | ||
| 881 | 893 | #ifdef SBR_DEC |
| 882 | 894 | if ((hDecoder->sbr_present_flag == 1) || (hDecoder->forceUpSampling == 1)) |
| 883 | 895 | { |
| 896 | + uint8_t ele; | |
| 897 | + | |
| 884 | 898 | /* this data is different when SBR is used or when the data is upsampled */ |
| 885 | 899 | frame_len *= 2; |
| 886 | 900 | hInfo->samples *= 2; |
| 887 | 901 | hInfo->samplerate *= 2; |
| 888 | 902 | |
| 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 | + | |
| 889 | 913 | /* sbr */ |
| 890 | 914 | if (hDecoder->sbr_present_flag == 1) |
| 891 | 915 | { |