flacdec: Avoid busy loop.
authorAndre Noll <maan@systemlinux.org>
Tue, 3 Sep 2013 22:55:21 +0000 (22:55 +0000)
committerAndre Noll <maan@systemlinux.org>
Sun, 27 Oct 2013 08:40:10 +0000 (09:40 +0100)
May happen when the last frame of a stream is incomplete.

flacdec_filter.c

index b51ac3bdee671dba91dc444fdd333126a912677a..01937e93f7fdbf2897e4404ffbb9e7781af392bd 100644 (file)
@@ -63,6 +63,16 @@ static FLAC__StreamDecoderReadStatus read_cb(
        }
        if (*bytes > 0)
                return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
+       /**
+       * Nothing was copied. If the input queue of the btrn is smaller than
+       * the minimal input queue size, our parent must have been gone, so
+       * we're not going to get more input. Since our remaining data is not
+       * sufficient do decode a single frame, we have an EOF condition.
+       */
+       if (btr_get_input_queue_size(btrn) < fn->min_iqs) {
+               assert(btr_no_parent(btrn));
+               return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
+       }
        /*
         * We are kind of screwed here. Returning CONTINUE with a byte count of
         * zero leads to an endless loop, so we must return either EOF or