vorbisdec: Check memory allocations
authorVittorio Giovara <vittorio.giovara@gmail.com>
Mon, 2 Feb 2015 00:57:15 +0000 (01:57 +0100)
committerVittorio Giovara <vittorio.giovara@gmail.com>
Tue, 17 Feb 2015 17:16:43 +0000 (12:16 -0500)
libavcodec/vorbisdec.c

index dbcc1cd..d52bfd5 100644 (file)
@@ -369,10 +369,15 @@ static int vorbis_parse_setup_hdr_codebooks(vorbis_context *vc)
             }
 
 // Weed out unused vlcs and build codevector vector
-            codebook_setup->codevectors = used_entries ? av_mallocz(used_entries *
-                                                                    codebook_setup->dimensions *
-                                                                    sizeof(*codebook_setup->codevectors))
-                                                       : NULL;
+            if (used_entries) {
+                codebook_setup->codevectors =
+                    av_mallocz(used_entries * codebook_setup->dimensions *
+                               sizeof(*codebook_setup->codevectors));
+                if (!codebook_setup->codevectors)
+                    return AVERROR(ENOMEM);
+            } else
+                codebook_setup->codevectors = NULL;
+
             for (j = 0, i = 0; i < entries; ++i) {
                 unsigned dim = codebook_setup->dimensions;