aacdec: Fix a brown paper bag bug.
authorAndre Noll <maan@systemlinux.org>
Mon, 26 Jul 2010 11:05:42 +0000 (13:05 +0200)
committerAndre Noll <maan@systemlinux.org>
Mon, 26 Jul 2010 11:05:42 +0000 (13:05 +0200)
Oops, we were using PARA_MAX() instead of PARA_MIN() to determine
the number of bytes to convert in the next run.  This silly bug could
lead to a segfault in the aacdec filter. Moreover, the assertion in
buffer_tree.c that would have caught the bug was _also_ b0rken.

But it's not my fault. I blame Grover of the Sesame street for both
bugs. He did explain the difference between near and far, although
this knowledge is next to useless for a programmer. And he did not
say a single word about MIN and MAX, or true and false. No wonder
such bugs happen.

aacdec_filter.c
buffer_tree.c

index f33f21eb7a63479e87c17cafb1d7fad0f6bce19b..5b84d07e12c4757c4393e0d5da54a3bcbed499a9 100644 (file)
@@ -112,7 +112,7 @@ next_buffer:
                return;
        btr_merge(btrn, fn->min_iqs);
        len = btr_next_buffer(btrn, (char **)&inbuf);
-       len = PARA_MAX(len, (size_t)8192);
+       len = PARA_MIN(len, (size_t)8192);
        consumed = 0;
        iqs = btr_get_input_queue_size(btrn);
        if (!padd->initialized) {
@@ -186,7 +186,8 @@ next_buffer:
                        padd->frame_info.bytesconsumed);
                PARA_ERROR_LOG("%s\n", NeAACDecGetErrorMessage(
                        padd->frame_info.error));
-               consumed++; /* catch 21 */
+               if (consumed < len)
+                       consumed++; /* catch 21 */
                goto success;
        }
        padd->error_count = 0;
index 3a59f8b5e2e20fa20c94117dd31e2655101936cf..d92d9863e10e2b4081fba91a35b06233933a15cc 100644 (file)
@@ -634,7 +634,7 @@ void btr_consume(struct btr_node *btrn, size_t numbytes)
                        numbytes -= br->btrb->size - br->consumed;
                        btr_drop_buffer_reference(br);
                }
-               assert(true);
+               assert(false);
        }
        /*
         * We have a wrap buffer, consume from it. If in total, i.e. including