shithub: aacdec

Download patch

ref: 323eccb93a870117de76b97aace1958f61e36139
parent: 24ea3e1ec9b06738df21731fbf4ce344a53b5432
author: menno <menno>
date: Sun Apr 13 14:27:10 EDT 2003

more bitstream error resilience

--- a/libfaad/error.c
+++ b/libfaad/error.c
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: error.c,v 1.8 2003/02/16 18:17:11 menno Exp $
+** $Id: error.c,v 1.9 2003/04/13 18:27:09 menno Exp $
 **/
 
 #include "common.h"
@@ -37,5 +37,7 @@
     "Non existent huffman codebook number found",
     "Maximum number of channels exceeded",
     "Maximum number of bitstream elements exceeded",
-    "Input data buffer too small"
+    "Input data buffer too small",
+    "Array index out of range",
+    "Maximum number of scalefactor bands exceeded"
 };
\ No newline at end of file
--- a/libfaad/pulse.c
+++ b/libfaad/pulse.c
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: pulse.c,v 1.4 2003/04/02 18:31:07 menno Exp $
+** $Id: pulse.c,v 1.5 2003/04/13 18:27:09 menno Exp $
 **/
 
 #include "common.h"
@@ -25,7 +25,7 @@
 #include "syntax.h"
 #include "pulse.h"
 
-void pulse_decode(ic_stream *ics, int16_t *spec_data, uint16_t framelen)
+uint8_t pulse_decode(ic_stream *ics, int16_t *spec_data, uint16_t framelen)
 {
     uint8_t i;
     uint16_t k;
@@ -37,7 +37,7 @@
         k += pul->pulse_offset[i];
 
         if (k >= framelen)
-            return; /* should not be possible */
+            return 15; /* should not be possible */
 
         if (spec_data[k] > 0)
             spec_data[k] += pul->pulse_amp[i];
@@ -44,4 +44,6 @@
         else
             spec_data[k] -= pul->pulse_amp[i];
     }
+
+    return 0;
 }
--- a/libfaad/pulse.h
+++ b/libfaad/pulse.h
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: pulse.h,v 1.3 2003/04/02 18:31:07 menno Exp $
+** $Id: pulse.h,v 1.4 2003/04/13 18:27:09 menno Exp $
 **/
 
 #ifndef __PULSE_H__
@@ -26,7 +26,7 @@
 extern "C" {
 #endif
 
-void pulse_decode(ic_stream *ics, int16_t *spec_coef, uint16_t framelen);
+uint8_t pulse_decode(ic_stream *ics, int16_t *spec_coef, uint16_t framelen);
 
 #ifdef __cplusplus
 }
--- a/libfaad/syntax.c
+++ b/libfaad/syntax.c
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: syntax.c,v 1.42 2003/04/02 19:09:49 menno Exp $
+** $Id: syntax.c,v 1.43 2003/04/13 18:27:09 menno Exp $
 **/
 
 /*
@@ -505,9 +505,12 @@
         if (ics->pulse_data_present)
         {
             if (ics->window_sequence != EIGHT_SHORT_SEQUENCE)
-                pulse_decode(ics, spec_data, hDecoder->frameLength);
-            else
+            {
+                if ((result = pulse_decode(ics, spec_data, hDecoder->frameLength)) > 0)
+                    return result;
+            } else {
                 return 2; /* pulse coding not allowed for short blocks */
+            }
         }
         return 0;
     } else
@@ -615,16 +618,22 @@
         if (ics1->pulse_data_present)
         {
             if (ics1->window_sequence != EIGHT_SHORT_SEQUENCE)
-                pulse_decode(ics1, spec_data1, hDecoder->frameLength);
-            else
+            {
+                if ((result = pulse_decode(ics1, spec_data1, hDecoder->frameLength)) > 0)
+                    return result;
+            } else {
                 return 2; /* pulse coding not allowed for short blocks */
+            }
         }
         if (ics2->pulse_data_present)
         {
             if (ics2->window_sequence != EIGHT_SHORT_SEQUENCE)
-                pulse_decode(ics2, spec_data2, hDecoder->frameLength);
-            else
+            {
+                if ((result = pulse_decode(ics2, spec_data2, hDecoder->frameLength)) > 0)
+                    return result;
+            } else {
                 return 2; /* pulse coding not allowed for short blocks */
+            }
         }
         return 0;
     } else
@@ -658,12 +667,13 @@
     }
 
     /* get the grouping information */
-    retval = window_grouping_info(hDecoder, ics);
+    if ((retval = window_grouping_info(hDecoder, ics)) > 0)
+        return retval;
 
     /* should be an error */
     /* check the range of max_sfb */
     if (ics->max_sfb > ics->num_swb)
-        ics->max_sfb = ics->num_swb;
+        return 16;
 
     if (ics->window_sequence != EIGHT_SHORT_SEQUENCE)
     {
@@ -726,7 +736,7 @@
 }
 
 /* Table 4.4.7 */
-static void pulse_data(ic_stream *ics, pulse_info *pul, bitfile *ld)
+static uint8_t pulse_data(ic_stream *ics, pulse_info *pul, bitfile *ld)
 {
     uint8_t i;
 
@@ -737,7 +747,7 @@
 
     /* check the range of pulse_start_sfb */
     if (pul->pulse_start_sfb > ics->num_swb)
-        pul->pulse_start_sfb = ics->num_swb;
+        return 16;
 
     for (i = 0; i < pul->number_pulse+1; i++)
     {
@@ -746,6 +756,8 @@
         pul->pulse_amp[i] = (uint8_t)faad_getbits(ld, 4
             DEBUGVAR(1,59,"pulse_data(): pulse_amp"));
     }
+
+    return 0;
 }
 
 /* Table 4.4.10 */
@@ -909,7 +921,10 @@
         if ((result = ics_info(hDecoder, ics, ld, ele->common_window)) > 0)
             return result;
     }
-    section_data(hDecoder, ics, ld);
+
+    if ((result = section_data(hDecoder, ics, ld)) > 0)
+        return result;
+
     if ((result = scale_factor_data(hDecoder, ics, ld)) > 0)
         return result;
 
@@ -924,7 +939,8 @@
         if ((ics->pulse_data_present = faad_get1bit(ld
             DEBUGVAR(1,68,"individual_channel_stream(): pulse_data_present"))) & 1)
         {
-            pulse_data(ics, &(ics->pul), ld);
+            if ((result = pulse_data(ics, &(ics->pul), ld)) > 0)
+                return result;
         }
 
         /* get tns data */
@@ -1013,9 +1029,12 @@
     if (ics->pulse_data_present)
     {
         if (ics->window_sequence != EIGHT_SHORT_SEQUENCE)
-            pulse_decode(ics, spec_data, hDecoder->frameLength);
-        else
+        {
+            if ((result = pulse_decode(ics, spec_data, hDecoder->frameLength)) > 0)
+                return result;
+        } else {
             return 2; /* pulse coding not allowed for short blocks */
+        }
     }
 
     return 0;
@@ -1022,7 +1041,7 @@
 }
 
 /* Table 4.4.25 */
-static void section_data(faacDecHandle hDecoder, ic_stream *ics, bitfile *ld)
+static uint8_t section_data(faacDecHandle hDecoder, ic_stream *ics, bitfile *ld)
 {
     uint8_t g;
     uint8_t sect_esc_val, sect_bits;
@@ -1053,6 +1072,11 @@
             uint16_t sect_len = 0;
             uint8_t sect_cb_bits = 4;
 
+            /* if "faad_getbits" detects error and returns "0", "k" is never
+               incremented and we cannot leave the while loop */
+            if ((ld->error != 0) || (ld->no_more_reading))
+                return 14;
+
 #ifdef ERROR_RESILIENCE
             if (hDecoder->aacSectionDataResilienceFlag)
                 sect_cb_bits = 5;
@@ -1115,6 +1139,8 @@
 #if 0
     printf("\n");
 #endif
+
+    return 0;
 }
 
 /*
--- a/libfaad/syntax.h
+++ b/libfaad/syntax.h
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: syntax.h,v 1.26 2003/04/01 16:34:35 menno Exp $
+** $Id: syntax.h,v 1.27 2003/04/13 18:27:10 menno Exp $
 **/
 
 #ifndef __SYNTAX_H__
@@ -102,7 +102,7 @@
                                          int16_t *spec_data);
 static uint8_t ics_info(faacDecHandle hDecoder, ic_stream *ics, bitfile *ld,
                         uint8_t common_window);
-static void section_data(faacDecHandle hDecoder, ic_stream *ics, bitfile *ld);
+static uint8_t section_data(faacDecHandle hDecoder, ic_stream *ics, bitfile *ld);
 static uint8_t scale_factor_data(faacDecHandle hDecoder, ic_stream *ics, bitfile *ld);
 static void gain_control_data(bitfile *ld, ic_stream *ics);
 static uint8_t spectral_data(faacDecHandle hDecoder, ic_stream *ics, bitfile *ld,
@@ -112,7 +112,7 @@
 uint8_t reordered_spectral_data(faacDecHandle hDecoder, ic_stream *ics,
                                 bitfile *ld, int16_t *spectral_data);
 #endif
-static void pulse_data(ic_stream *ics, pulse_info *pul, bitfile *ld);
+static uint8_t pulse_data(ic_stream *ics, pulse_info *pul, bitfile *ld);
 static void tns_data(ic_stream *ics, tns_info *tns, bitfile *ld);
 static void ltp_data(faacDecHandle hDecoder, ic_stream *ics, ltp_info *ltp, bitfile *ld);
 static uint8_t adts_fixed_header(adts_header *adts, bitfile *ld);