[FFmpeg-cvslog] alac: check for truncated packets

Justin Ruggles git at videolan.org
Sat Jul 28 00:10:48 CEST 2012


ffmpeg | branch: master | Justin Ruggles <justin.ruggles at gmail.com> | Thu Jul 19 20:04:40 2012 -0400| [81f548de572a324c771c094291378d9bcc184af3] | committer: Justin Ruggles

alac: check for truncated packets

This will give a clearer error message when the error is caused by a
truncated packet.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=81f548de572a324c771c094291378d9bcc184af3
---

 libavcodec/alac.c |   15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index 1756cdf..61d2e70 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -432,16 +432,19 @@ static int alac_decode_frame(AVCodecContext *avctx, void *data,
     ALACContext *alac = avctx->priv_data;
     enum RawDataBlockType element;
     int channels;
-    int ch, ret;
+    int ch, ret, got_end;
 
     init_get_bits(&alac->gb, avpkt->data, avpkt->size * 8);
 
+    got_end = 0;
     alac->nb_samples = 0;
     ch = 0;
-    while (get_bits_left(&alac->gb)) {
+    while (get_bits_left(&alac->gb) >= 3) {
         element = get_bits(&alac->gb, 3);
-        if (element == TYPE_END)
+        if (element == TYPE_END) {
+            got_end = 1;
             break;
+        }
         if (element > TYPE_CPE && element != TYPE_LFE) {
             av_log(avctx, AV_LOG_ERROR, "syntax element unsupported: %d", element);
             return AVERROR_PATCHWELCOME;
@@ -456,11 +459,15 @@ static int alac_decode_frame(AVCodecContext *avctx, void *data,
         ret = decode_element(avctx, data,
                              alac_channel_layout_offsets[alac->channels - 1][ch],
                              channels);
-        if (ret < 0)
+        if (ret < 0 && get_bits_left(&alac->gb))
             return ret;
 
         ch += channels;
     }
+    if (!got_end) {
+        av_log(avctx, AV_LOG_ERROR, "no end tag found. incomplete packet.\n");
+        return AVERROR_INVALIDDATA;
+    }
 
     if (avpkt->size * 8 - get_bits_count(&alac->gb) > 8) {
         av_log(avctx, AV_LOG_ERROR, "Error : %d bits left\n",



More information about the ffmpeg-cvslog mailing list