Browse code

avienc: fix AVI stream index for files with >10 streams

Fixes issue 2563.

Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
(cherry picked from commit 4acc94e97a9551d11ead29735e23283d71f1d4c2)

longstone authored on 2011/02/24 00:43:21
Showing 2 changed files
... ...
@@ -32,6 +32,7 @@
32 32
 
33 33
 #define AVI_MAX_RIFF_SIZE       0x40000000LL
34 34
 #define AVI_MASTER_INDEX_SIZE   256
35
+#define AVI_MAX_STREAM_COUNT    100
35 36
 
36 37
 /* index flags */
37 38
 #define AVIIF_INDEX             0x10
... ...
@@ -85,8 +85,8 @@ static int64_t avi_start_new_riff(AVFormatContext *s, AVIOContext *pb,
85 85
 
86 86
 static char* avi_stream2fourcc(char* tag, int index, enum AVMediaType type)
87 87
 {
88
-    tag[0] = '0';
89
-    tag[1] = '0' + index;
88
+    tag[0] = '0' + index/10;
89
+    tag[1] = '0' + index%10;
90 90
     if (type == AVMEDIA_TYPE_VIDEO) {
91 91
         tag[2] = 'd';
92 92
         tag[3] = 'c';
... ...
@@ -158,6 +158,12 @@ static int avi_write_header(AVFormatContext *s)
158 158
     int64_t list1, list2, strh, strf;
159 159
     AVMetadataTag *t = NULL;
160 160
 
161
+    if (s->nb_streams > AVI_MAX_STREAM_COUNT) {
162
+        av_log(s, AV_LOG_ERROR, "AVI does not support >%d streams\n",
163
+               AVI_MAX_STREAM_COUNT);
164
+        return -1;
165
+    }
166
+
161 167
     for(n=0;n<s->nb_streams;n++) {
162 168
         s->streams[n]->priv_data= av_mallocz(sizeof(AVIStream));
163 169
         if(!s->streams[n]->priv_data)