bitstream: Abort on invalid codes
authorAndre Noll <maan@systemlinux.org>
Sun, 18 Oct 2009 13:07:26 +0000 (15:07 +0200)
committerAndre Noll <maan@systemlinux.org>
Wed, 18 Nov 2009 18:34:20 +0000 (19:34 +0100)
bitstream.c
error.h

index 2522b6d..1142948 100644 (file)
@@ -57,7 +57,7 @@ static int build_table(struct vlc *vlc, int table_nb_bits, int nb_codes,
                const void *bits, const void *codes, int codes_wrap,
                int codes_size, uint32_t code_prefix, int n_prefix)
 {
-       int ret, i, j, k, n, table_size, table_index, nb, n1, idx, code_prefix2,
+       int i, j, k, n, table_size, table_index, nb, n1, idx, code_prefix2,
                symbol;
        uint32_t code;
        VLC_TYPE(*table)[2];
@@ -72,7 +72,7 @@ static int build_table(struct vlc *vlc, int table_nb_bits, int nb_codes,
                table[i][0] = -1;       //codes
        }
 
-       /* first pass: map codes and compute auxillary table sizes */
+       /* map codes and compute auxillary table sizes */
        for (i = 0; i < nb_codes; i++) {
                GET_DATA(n, bits, i, 1, 1);
                GET_DATA(code, codes, i, codes_wrap, codes_size);
@@ -89,8 +89,10 @@ static int build_table(struct vlc *vlc, int table_nb_bits, int nb_codes,
                                j = (code << (table_nb_bits - n)) & (table_size - 1);
                                nb = 1 << (table_nb_bits - n);
                                for (k = 0; k < nb; k++) {
-                                       if (table[j][1] /* bits */ != 0)
-                                               return -E_BAD_CODES;
+                                       if (table[j][1] /* bits */ != 0) {
+                                               PARA_EMERG_LOG("detected incorrect code\n");
+                                               exit(EXIT_FAILURE);
+                                       }
                                        table[j][1] = n;        //bits
                                        table[j][0] = symbol;
                                        j++;
@@ -107,7 +109,7 @@ static int build_table(struct vlc *vlc, int table_nb_bits, int nb_codes,
                }
        }
 
-       /* second pass : fill auxillary tables recursively */
+       /* fill auxillary tables recursively */
        for (i = 0; i < table_size; i++) {
                n = table[i][1];        //bits
                if (n < 0) {
@@ -116,14 +118,11 @@ static int build_table(struct vlc *vlc, int table_nb_bits, int nb_codes,
                                n = table_nb_bits;
                                table[i][1] = -n;       //bits
                        }
-                       ret = build_table(vlc, n, nb_codes,
+                       idx = build_table(vlc, n, nb_codes,
                                bits, codes, codes_wrap, codes_size,
                                (code_prefix << table_nb_bits) | i,
                                n_prefix + table_nb_bits);
-                       if (ret < 0)
-                               return ret;
-                       idx = ret;
-                       /* note: realloc has been done, so reload tables */
+                       /* vlc->table might have changed */
                        table = &vlc->table[table_index];
                        table[i][0] = idx;      //code
                }
diff --git a/error.h b/error.h
index 92e501c..ee5bac3 100644 (file)
--- a/error.h
+++ b/error.h
@@ -34,6 +34,7 @@ DEFINE_ERRLIST_OBJECT_ENUM;
 #define SERVER_COMMAND_LIST_ERRORS
 #define AFS_COMMAND_LIST_ERRORS
 #define AUDIOD_COMMAND_LIST_ERRORS
+#define BITSTREAM_ERRORS
 
 extern const char **para_errlist[];
 
@@ -54,10 +55,6 @@ extern const char **para_errlist[];
        PARA_ERROR(INCOHERENT_BLOCK_LEN, "incoherent block length"), \
 
 
-#define BITSTREAM_ERRORS \
-       PARA_ERROR(BAD_CODES, "detected incorrect codes")
-
-
 #define IMDCT_ERRORS \
        PARA_ERROR(FFT_BAD_PARAMS, "invalid params for fft"), \