View | Details | Raw Unified | Return to bug 228141
Collapse All | Expand All

(-)Makefile (+1 lines)
Lines 3-8 Link Here
3
3
4
PORTNAME=	wavpack
4
PORTNAME=	wavpack
5
PORTVERSION=	5.1.0
5
PORTVERSION=	5.1.0
6
PORTREVISION=	1
6
CATEGORIES=	audio
7
CATEGORIES=	audio
7
MASTER_SITES=	http://www.wavpack.com/
8
MASTER_SITES=	http://www.wavpack.com/
8
9
(-)files/patch-CVE-2018-10536_10537 (+63 lines)
Line 0 Link Here
1
From 26cb47f99d481ad9b93eeff80d26e6b63bbd7e15 Mon Sep 17 00:00:00 2001
2
From: David Bryant <david@wavpack.com>
3
Date: Tue, 24 Apr 2018 22:18:07 -0700
4
Subject: [PATCH 6/6] issue #30 issue #31 issue #32: no multiple format chunks
5
 in WAV or W64
6
7
---
8
 cli/riff.c   | 7 ++++++-
9
 cli/wave64.c | 6 ++++++
10
 2 files changed, 12 insertions(+), 1 deletion(-)
11
12
diff --git cli/riff.c cli/riff.c
13
index 7bddf63..5d6452e 100644
14
--- cli/riff.c
15
+++ cli/riff.c
16
@@ -53,7 +53,7 @@ extern int debug_logging_mode;
17
 
18
 int ParseRiffHeaderConfig (FILE *infile, char *infilename, char *fourcc, WavpackContext *wpc, WavpackConfig *config)
19
 {
20
-    int is_rf64 = !strncmp (fourcc, "RF64", 4), got_ds64 = 0;
21
+    int is_rf64 = !strncmp (fourcc, "RF64", 4), got_ds64 = 0, format_chunk = 0;
22
     int64_t total_samples = 0, infilesize;
23
     RiffChunkHeader riff_chunk_header;
24
     ChunkHeader chunk_header;
25
@@ -140,6 +140,11 @@ int ParseRiffHeaderConfig (FILE *infile, char *infilename, char *fourcc, Wavpack
26
         else if (!strncmp (chunk_header.ckID, "fmt ", 4)) {     // if it's the format chunk, we want to get some info out of there and
27
             int supported = TRUE, format;                        // make sure it's a .wav file we can handle
28
 
29
+            if (format_chunk++) {
30
+                error_line ("%s is not a valid .WAV file!", infilename);
31
+                return WAVPACK_SOFT_ERROR;
32
+            }
33
+
34
             if (chunk_header.ckSize < 16 || chunk_header.ckSize > sizeof (WaveHeader) ||
35
                 !DoReadFile (infile, &WaveHeader, chunk_header.ckSize, &bcount) ||
36
                 bcount != chunk_header.ckSize) {
37
diff --git cli/wave64.c cli/wave64.c
38
index fa928a0..0388dc7 100644
39
--- cli/wave64.c
40
+++ cli/wave64.c
41
@@ -53,6 +53,7 @@ int ParseWave64HeaderConfig (FILE *infile, char *infilename, char *fourcc, Wavpa
42
     Wave64ChunkHeader chunk_header;
43
     Wave64FileHeader filehdr;
44
     WaveHeader WaveHeader;
45
+    int format_chunk = 0;
46
     uint32_t bcount;
47
 
48
     infilesize = DoGetFileSize (infile);
49
@@ -104,6 +105,11 @@ int ParseWave64HeaderConfig (FILE *infile, char *infilename, char *fourcc, Wavpa
50
         if (!memcmp (chunk_header.ckID, fmt_guid, sizeof (fmt_guid))) {
51
             int supported = TRUE, format;
52
 
53
+            if (format_chunk++) {
54
+                error_line ("%s is not a valid .W64 file!", infilename);
55
+                return WAVPACK_SOFT_ERROR;
56
+            }
57
+
58
             chunk_header.ckSize = (chunk_header.ckSize + 7) & ~7L;
59
 
60
             if (chunk_header.ckSize < 16 || chunk_header.ckSize > sizeof (WaveHeader) ||
61
-- 
62
2.17.0
63
(-)files/patch-CVE-2018-10538_10539_10540 (+75 lines)
Line 0 Link Here
1
From 6f8bb34c2993a48ab9afbe353e6d0cff7c8d821d Mon Sep 17 00:00:00 2001
2
From: David Bryant <david@wavpack.com>
3
Date: Tue, 24 Apr 2018 17:27:01 -0700
4
Subject: [PATCH 5/6] issue #33, sanitize size of unknown chunks before
5
 malloc()
6
7
---
8
 cli/dsdiff.c | 9 ++++++++-
9
 cli/riff.c   | 9 ++++++++-
10
 cli/wave64.c | 9 ++++++++-
11
 3 files changed, 24 insertions(+), 3 deletions(-)
12
13
diff --git cli/dsdiff.c cli/dsdiff.c
14
index c016df9..fa56bbb 100644
15
--- cli/dsdiff.c
16
+++ cli/dsdiff.c
17
@@ -279,7 +279,14 @@ int ParseDsdiffHeaderConfig (FILE *infile, char *infilename, char *fourcc, Wavpa
18
         else {          // just copy unknown chunks to output file
19
 
20
             int bytes_to_copy = (int)(((dff_chunk_header.ckDataSize) + 1) & ~(int64_t)1);
21
-            char *buff = malloc (bytes_to_copy);
22
+            char *buff;
23
+
24
+            if (bytes_to_copy < 0 || bytes_to_copy > 4194304) {
25
+                error_line ("%s is not a valid .DFF file!", infilename);
26
+                return WAVPACK_SOFT_ERROR;
27
+            }
28
+
29
+            buff = malloc (bytes_to_copy);
30
 
31
             if (debug_logging_mode)
32
                 error_line ("extra unknown chunk \"%c%c%c%c\" of %d bytes",
33
diff --git cli/riff.c cli/riff.c
34
index de98c1e..7bddf63 100644
35
--- cli/riff.c
36
+++ cli/riff.c
37
@@ -286,7 +286,14 @@ int ParseRiffHeaderConfig (FILE *infile, char *infilename, char *fourcc, Wavpack
38
         else {          // just copy unknown chunks to output file
39
 
40
             int bytes_to_copy = (chunk_header.ckSize + 1) & ~1L;
41
-            char *buff = malloc (bytes_to_copy);
42
+            char *buff;
43
+
44
+            if (bytes_to_copy < 0 || bytes_to_copy > 4194304) {
45
+                error_line ("%s is not a valid .WAV file!", infilename);
46
+                return WAVPACK_SOFT_ERROR;
47
+            }
48
+
49
+            buff = malloc (bytes_to_copy);
50
 
51
             if (debug_logging_mode)
52
                 error_line ("extra unknown chunk \"%c%c%c%c\" of %d bytes",
53
diff --git cli/wave64.c cli/wave64.c
54
index 591d640..fa928a0 100644
55
--- cli/wave64.c
56
+++ cli/wave64.c
57
@@ -241,7 +241,14 @@ int ParseWave64HeaderConfig (FILE *infile, char *infilename, char *fourcc, Wavpa
58
         }
59
         else {          // just copy unknown chunks to output file
60
             int bytes_to_copy = (chunk_header.ckSize + 7) & ~7L;
61
-            char *buff = malloc (bytes_to_copy);
62
+            char *buff;
63
+
64
+            if (bytes_to_copy < 0 || bytes_to_copy > 4194304) {
65
+                error_line ("%s is not a valid .W64 file!", infilename);
66
+                return WAVPACK_SOFT_ERROR;
67
+            }
68
+
69
+            buff = malloc (bytes_to_copy);
70
 
71
             if (debug_logging_mode)
72
                 error_line ("extra unknown chunk \"%c%c%c%c\" of %d bytes",
73
-- 
74
2.17.0
75
(-)files/patch-CVE-2018-6767 (+115 lines)
Line 0 Link Here
1
From d5bf76b5a88d044a1be1d5656698e3ba737167e5 Mon Sep 17 00:00:00 2001
2
From: David Bryant <david@wavpack.com>
3
Date: Sun, 4 Feb 2018 11:28:15 -0800
4
Subject: [PATCH 1/6] issue #27, do not overwrite stack on corrupt RF64 file
5
6
---
7
 cli/riff.c | 39 ++++++++++++++++++++++++++++++++-------
8
 1 file changed, 32 insertions(+), 7 deletions(-)
9
10
diff --git cli/riff.c cli/riff.c
11
index 8b1af45..de98c1e 100644
12
--- cli/riff.c
13
+++ cli/riff.c
14
@@ -42,6 +42,7 @@ typedef struct {
15
 
16
 #pragma pack(pop)
17
 
18
+#define CS64ChunkFormat "4D"
19
 #define DS64ChunkFormat "DDDL"
20
 
21
 #define WAVPACK_NO_ERROR    0
22
@@ -101,13 +102,13 @@ int ParseRiffHeaderConfig (FILE *infile, char *infilename, char *fourcc, Wavpack
23
 
24
         if (!strncmp (chunk_header.ckID, "ds64", 4)) {
25
             if (chunk_header.ckSize < sizeof (DS64Chunk) ||
26
-                !DoReadFile (infile, &ds64_chunk, chunk_header.ckSize, &bcount) ||
27
-                bcount != chunk_header.ckSize) {
28
+                !DoReadFile (infile, &ds64_chunk, sizeof (DS64Chunk), &bcount) ||
29
+                bcount != sizeof (DS64Chunk)) {
30
                     error_line ("%s is not a valid .WAV file!", infilename);
31
                     return WAVPACK_SOFT_ERROR;
32
             }
33
             else if (!(config->qmode & QMODE_NO_STORE_WRAPPER) &&
34
-                !WavpackAddWrapper (wpc, &ds64_chunk, chunk_header.ckSize)) {
35
+                !WavpackAddWrapper (wpc, &ds64_chunk, sizeof (DS64Chunk))) {
36
                     error_line ("%s", WavpackGetErrorMessage (wpc));
37
                     return WAVPACK_SOFT_ERROR;
38
             }
39
@@ -315,10 +316,11 @@ int ParseRiffHeaderConfig (FILE *infile, char *infilename, char *fourcc, Wavpack
40
 
41
 int WriteRiffHeader (FILE *outfile, WavpackContext *wpc, int64_t total_samples, int qmode)
42
 {
43
-    int do_rf64 = 0, write_junk = 1;
44
+    int do_rf64 = 0, write_junk = 1, table_length = 0;
45
     ChunkHeader ds64hdr, datahdr, fmthdr;
46
     RiffChunkHeader riffhdr;
47
     DS64Chunk ds64_chunk;
48
+    CS64Chunk cs64_chunk;
49
     JunkChunk junkchunk;
50
     WaveHeader wavhdr;
51
     uint32_t bcount;
52
@@ -380,6 +382,7 @@ int WriteRiffHeader (FILE *outfile, WavpackContext *wpc, int64_t total_samples,
53
     strncpy (riffhdr.formType, "WAVE", sizeof (riffhdr.formType));
54
     total_riff_bytes = sizeof (riffhdr) + wavhdrsize + sizeof (datahdr) + ((total_data_bytes + 1) & ~(int64_t)1);
55
     if (do_rf64) total_riff_bytes += sizeof (ds64hdr) + sizeof (ds64_chunk);
56
+    total_riff_bytes += table_length * sizeof (CS64Chunk);
57
     if (write_junk) total_riff_bytes += sizeof (junkchunk);
58
     strncpy (fmthdr.ckID, "fmt ", sizeof (fmthdr.ckID));
59
     strncpy (datahdr.ckID, "data", sizeof (datahdr.ckID));
60
@@ -394,11 +397,12 @@ int WriteRiffHeader (FILE *outfile, WavpackContext *wpc, int64_t total_samples,
61
 
62
     if (do_rf64) {
63
         strncpy (ds64hdr.ckID, "ds64", sizeof (ds64hdr.ckID));
64
-        ds64hdr.ckSize = sizeof (ds64_chunk);
65
+        ds64hdr.ckSize = sizeof (ds64_chunk) + (table_length * sizeof (CS64Chunk));
66
         CLEAR (ds64_chunk);
67
         ds64_chunk.riffSize64 = total_riff_bytes;
68
         ds64_chunk.dataSize64 = total_data_bytes;
69
         ds64_chunk.sampleCount64 = total_samples;
70
+        ds64_chunk.tableLength = table_length;
71
         riffhdr.ckSize = (uint32_t) -1;
72
         datahdr.ckSize = (uint32_t) -1;
73
         WavpackNativeToLittleEndian (&ds64hdr, ChunkHeaderFormat);
74
@@ -409,6 +413,14 @@ int WriteRiffHeader (FILE *outfile, WavpackContext *wpc, int64_t total_samples,
75
         datahdr.ckSize = (uint32_t) total_data_bytes;
76
     }
77
 
78
+    // this "table" is just a dummy placeholder for testing (normally not written)
79
+
80
+    if (table_length) {
81
+        strncpy (cs64_chunk.ckID, "dmmy", sizeof (cs64_chunk.ckID));
82
+        cs64_chunk.chunkSize64 = 12345678;
83
+        WavpackNativeToLittleEndian (&cs64_chunk, CS64ChunkFormat);
84
+    }
85
+
86
     // write the RIFF chunks up to just before the data starts
87
 
88
     WavpackNativeToLittleEndian (&riffhdr, ChunkHeaderFormat);
89
@@ -418,8 +430,21 @@ int WriteRiffHeader (FILE *outfile, WavpackContext *wpc, int64_t total_samples,
90
 
91
     if (!DoWriteFile (outfile, &riffhdr, sizeof (riffhdr), &bcount) || bcount != sizeof (riffhdr) ||
92
         (do_rf64 && (!DoWriteFile (outfile, &ds64hdr, sizeof (ds64hdr), &bcount) || bcount != sizeof (ds64hdr))) ||
93
-        (do_rf64 && (!DoWriteFile (outfile, &ds64_chunk, sizeof (ds64_chunk), &bcount) || bcount != sizeof (ds64_chunk))) ||
94
-        (write_junk && (!DoWriteFile (outfile, &junkchunk, sizeof (junkchunk), &bcount) || bcount != sizeof (junkchunk))) ||
95
+        (do_rf64 && (!DoWriteFile (outfile, &ds64_chunk, sizeof (ds64_chunk), &bcount) || bcount != sizeof (ds64_chunk)))) {
96
+            error_line ("can't write .WAV data, disk probably full!");
97
+            return FALSE;
98
+    }
99
+
100
+    // again, this is normally not written except for testing
101
+
102
+    while (table_length--)
103
+        if (!DoWriteFile (outfile, &cs64_chunk, sizeof (cs64_chunk), &bcount) || bcount != sizeof (cs64_chunk)) {
104
+            error_line ("can't write .WAV data, disk probably full!");
105
+            return FALSE;
106
+        }
107
+
108
+
109
+    if ((write_junk && (!DoWriteFile (outfile, &junkchunk, sizeof (junkchunk), &bcount) || bcount != sizeof (junkchunk))) ||
110
         !DoWriteFile (outfile, &fmthdr, sizeof (fmthdr), &bcount) || bcount != sizeof (fmthdr) ||
111
         !DoWriteFile (outfile, &wavhdr, wavhdrsize, &bcount) || bcount != wavhdrsize ||
112
         !DoWriteFile (outfile, &datahdr, sizeof (datahdr), &bcount) || bcount != sizeof (datahdr)) {
113
-- 
114
2.17.0
115
(-)files/patch-CVE-2018-7253 (+35 lines)
Line 0 Link Here
1
From 36a24c7881427d2e1e4dc1cef58f19eee0d13aec Mon Sep 17 00:00:00 2001
2
From: David Bryant <david@wavpack.com>
3
Date: Sat, 10 Feb 2018 16:01:39 -0800
4
Subject: [PATCH 2/6] issue #28, do not overwrite heap on corrupt DSDIFF file
5
6
---
7
 cli/dsdiff.c | 12 +++++++++++-
8
 1 file changed, 11 insertions(+), 1 deletion(-)
9
10
diff --git cli/dsdiff.c cli/dsdiff.c
11
index 410dc1c..c016df9 100644
12
--- cli/dsdiff.c
13
+++ cli/dsdiff.c
14
@@ -153,7 +153,17 @@ int ParseDsdiffHeaderConfig (FILE *infile, char *infilename, char *fourcc, Wavpa
15
                 error_line ("dsdiff file version = 0x%08x", version);
16
         }
17
         else if (!strncmp (dff_chunk_header.ckID, "PROP", 4)) {
18
-            char *prop_chunk = malloc ((size_t) dff_chunk_header.ckDataSize);
19
+            char *prop_chunk;
20
+
21
+            if (dff_chunk_header.ckDataSize < 4 || dff_chunk_header.ckDataSize > 1024) {
22
+                error_line ("%s is not a valid .DFF file!", infilename);
23
+                return WAVPACK_SOFT_ERROR;
24
+            }
25
+
26
+            if (debug_logging_mode)
27
+                error_line ("got PROP chunk of %d bytes total", (int) dff_chunk_header.ckDataSize);
28
+
29
+            prop_chunk = malloc ((size_t) dff_chunk_header.ckDataSize);
30
 
31
             if (!DoReadFile (infile, prop_chunk, (uint32_t) dff_chunk_header.ckDataSize, &bcount) ||
32
                 bcount != dff_chunk_header.ckDataSize) {
33
-- 
34
2.17.0
35
(-)files/patch-CVE-2018-7254 (+69 lines)
Line 0 Link Here
1
From 8e3fe45a7bac31d9a3b558ae0079e2d92a04799e Mon Sep 17 00:00:00 2001
2
From: David Bryant <david@wavpack.com>
3
Date: Sun, 11 Feb 2018 16:37:47 -0800
4
Subject: [PATCH 3/6] issue #28, fix buffer overflows and bad allocs on corrupt
5
 CAF files
6
7
---
8
 cli/caff.c | 30 +++++++++++++++++++++++-------
9
 1 file changed, 23 insertions(+), 7 deletions(-)
10
11
diff --git cli/caff.c cli/caff.c
12
index ae57c4b..6248a71 100644
13
--- cli/caff.c
14
+++ cli/caff.c
15
@@ -89,8 +89,8 @@ typedef struct
16
 
17
 #define CAFChannelDescriptionFormat "LLLLL"
18
 
19
-static const char TMH_full [] = { 1,2,3,13,9,10,5,6,12,14,15,16,17,9,4,18,7,8,19,20,21 };
20
-static const char TMH_std [] = { 1,2,3,11,8,9,5,6,10,12,13,14,15,7,4,16 };
21
+static const char TMH_full [] = { 1,2,3,13,9,10,5,6,12,14,15,16,17,9,4,18,7,8,19,20,21,0 };
22
+static const char TMH_std [] = { 1,2,3,11,8,9,5,6,10,12,13,14,15,7,4,16,0 };
23
 
24
 static struct {
25
     uint32_t mChannelLayoutTag;     // Core Audio layout, 100 - 146 in high word, num channels in low word
26
@@ -274,10 +274,19 @@ int ParseCaffHeaderConfig (FILE *infile, char *infilename, char *fourcc, Wavpack
27
             }
28
         }
29
         else if (!strncmp (caf_chunk_header.mChunkType, "chan", 4)) {
30
-            CAFChannelLayout *caf_channel_layout = malloc ((size_t) caf_chunk_header.mChunkSize);
31
+            CAFChannelLayout *caf_channel_layout;
32
 
33
-            if (caf_chunk_header.mChunkSize < sizeof (CAFChannelLayout) ||
34
-                !DoReadFile (infile, caf_channel_layout, (uint32_t) caf_chunk_header.mChunkSize, &bcount) ||
35
+            if (caf_chunk_header.mChunkSize < sizeof (CAFChannelLayout) || caf_chunk_header.mChunkSize > 1024) {
36
+                error_line ("this .CAF file has an invalid 'chan' chunk!");
37
+                return WAVPACK_SOFT_ERROR;
38
+            }
39
+
40
+            if (debug_logging_mode)
41
+                error_line ("'chan' chunk is %d bytes", (int) caf_chunk_header.mChunkSize);
42
+
43
+            caf_channel_layout = malloc ((size_t) caf_chunk_header.mChunkSize);
44
+
45
+            if (!DoReadFile (infile, caf_channel_layout, (uint32_t) caf_chunk_header.mChunkSize, &bcount) ||
46
                 bcount != caf_chunk_header.mChunkSize) {
47
                     error_line ("%s is not a valid .CAF file!", infilename);
48
                     free (caf_channel_layout);
49
@@ -495,8 +504,15 @@ int ParseCaffHeaderConfig (FILE *infile, char *infilename, char *fourcc, Wavpack
50
         }
51
         else {          // just copy unknown chunks to output file
52
 
53
-            int bytes_to_copy = (uint32_t) caf_chunk_header.mChunkSize;
54
-            char *buff = malloc (bytes_to_copy);
55
+            uint32_t bytes_to_copy = (uint32_t) caf_chunk_header.mChunkSize;
56
+            char *buff;
57
+
58
+            if (caf_chunk_header.mChunkSize < 0 || caf_chunk_header.mChunkSize > 1048576) {
59
+                error_line ("%s is not a valid .CAF file!", infilename);
60
+                return WAVPACK_SOFT_ERROR;
61
+            }
62
+
63
+            buff = malloc (bytes_to_copy);
64
 
65
             if (debug_logging_mode)
66
                 error_line ("extra unknown chunk \"%c%c%c%c\" of %d bytes",
67
-- 
68
2.17.0
69
(-)files/patch-fix-memory-leaks (+36 lines)
Line 0 Link Here
1
From 0a72951de8feaaf4c6e1740b5cb5cd0401b00464 Mon Sep 17 00:00:00 2001
2
From: David Bryant <david@wavpack.com>
3
Date: Sun, 8 Apr 2018 16:27:40 -0700
4
Subject: [PATCH 4/6] fix memory leaks
5
6
---
7
 src/common_utils.c | 13 +++++++++++++
8
 1 file changed, 13 insertions(+)
9
10
diff --git src/common_utils.c src/common_utils.c
11
index c53db91..f8ddc63 100644
12
--- src/common_utils.c
13
+++ src/common_utils.c
14
@@ -384,6 +384,19 @@ WavpackContext *WavpackCloseFile (WavpackContext *wpc)
15
 
16
     WavpackFreeWrapper (wpc);
17
 
18
+    if (wpc->metadata) {
19
+        int i;
20
+
21
+        for (i = 0; i < wpc->metacount; ++i)
22
+            if (wpc->metadata [i].data)
23
+                free (wpc->metadata [i].data);
24
+
25
+        free (wpc->metadata);
26
+    }
27
+
28
+    if (wpc->channel_identities)
29
+        free (wpc->channel_identities);
30
+
31
     if (wpc->channel_reordering)
32
         free (wpc->channel_reordering);
33
 
34
-- 
35
2.17.0
36

Return to bug 228141