diff --git a/libavformat/mov.c b/libavformat/mov.c
index 668ff89b4f86132778d2abcd3b11990e949b9ceb..e9404276855308f1cc805b9ba68d035627ec9347 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -87,10 +87,11 @@ static int mov_metadata_track_or_disc_number(MOVContext *c, AVIOContext *pb,
 {
     char buf[16];
 
-    short current, total;
+    short current, total = 0;
     avio_rb16(pb); // unknown
     current = avio_rb16(pb);
-    total = avio_rb16(pb);
+    if (len >= 6)
+        total = avio_rb16(pb);
     if (!total)
         snprintf(buf, sizeof(buf), "%d", current);
     else