summaryrefslogtreecommitdiffstats
path: root/meta-oe/recipes-multimedia/audiofile/files/0008-Check-for-multiplication-overflow-in-MSADPCM-decodeS.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta-oe/recipes-multimedia/audiofile/files/0008-Check-for-multiplication-overflow-in-MSADPCM-decodeS.patch')
-rw-r--r--meta-oe/recipes-multimedia/audiofile/files/0008-Check-for-multiplication-overflow-in-MSADPCM-decodeS.patch126
1 files changed, 126 insertions, 0 deletions
diff --git a/meta-oe/recipes-multimedia/audiofile/files/0008-Check-for-multiplication-overflow-in-MSADPCM-decodeS.patch b/meta-oe/recipes-multimedia/audiofile/files/0008-Check-for-multiplication-overflow-in-MSADPCM-decodeS.patch
new file mode 100644
index 0000000000..857ed78c59
--- /dev/null
+++ b/meta-oe/recipes-multimedia/audiofile/files/0008-Check-for-multiplication-overflow-in-MSADPCM-decodeS.patch
@@ -0,0 +1,126 @@
1From beacc44eb8cdf6d58717ec1a5103c5141f1b37f9 Mon Sep 17 00:00:00 2001
2From: Antonio Larrosa <larrosa@kde.org>
3Date: Mon, 6 Mar 2017 13:43:53 +0100
4Subject: [PATCH] Check for multiplication overflow in MSADPCM decodeSample
5
6Check for multiplication overflow (using __builtin_mul_overflow
7if available) in MSADPCM.cpp decodeSample and return an empty
8decoded block if an error occurs.
9
10This fixes the 00193-audiofile-signintoverflow-MSADPCM case of #41
11
12Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
13
14CVE: CVE-2017-6839
15Upstream-Status: Inactive-Upstream [lastrelease: 2013]
16Signed-off-by: Peter Marko <peter.marko@siemens.com>
17---
18 libaudiofile/modules/BlockCodec.cpp | 5 ++--
19 libaudiofile/modules/MSADPCM.cpp | 47 +++++++++++++++++++++++++++++++++----
20 2 files changed, 46 insertions(+), 6 deletions(-)
21
22diff --git a/libaudiofile/modules/BlockCodec.cpp b/libaudiofile/modules/BlockCodec.cpp
23index 45925e8..4731be1 100644
24--- a/libaudiofile/modules/BlockCodec.cpp
25+++ b/libaudiofile/modules/BlockCodec.cpp
26@@ -52,8 +52,9 @@ void BlockCodec::runPull()
27 // Decompress into m_outChunk.
28 for (int i=0; i<blocksRead; i++)
29 {
30- decodeBlock(static_cast<const uint8_t *>(m_inChunk->buffer) + i * m_bytesPerPacket,
31- static_cast<int16_t *>(m_outChunk->buffer) + i * m_framesPerPacket * m_track->f.channelCount);
32+ if (decodeBlock(static_cast<const uint8_t *>(m_inChunk->buffer) + i * m_bytesPerPacket,
33+ static_cast<int16_t *>(m_outChunk->buffer) + i * m_framesPerPacket * m_track->f.channelCount)==0)
34+ break;
35
36 framesRead += m_framesPerPacket;
37 }
38diff --git a/libaudiofile/modules/MSADPCM.cpp b/libaudiofile/modules/MSADPCM.cpp
39index 8ea3c85..ef9c38c 100644
40--- a/libaudiofile/modules/MSADPCM.cpp
41+++ b/libaudiofile/modules/MSADPCM.cpp
42@@ -101,24 +101,60 @@ static const int16_t adaptationTable[] =
43 768, 614, 512, 409, 307, 230, 230, 230
44 };
45
46+int firstBitSet(int x)
47+{
48+ int position=0;
49+ while (x!=0)
50+ {
51+ x>>=1;
52+ ++position;
53+ }
54+ return position;
55+}
56+
57+#ifndef __has_builtin
58+#define __has_builtin(x) 0
59+#endif
60+
61+int multiplyCheckOverflow(int a, int b, int *result)
62+{
63+#if (defined __GNUC__ && __GNUC__ >= 5) || ( __clang__ && __has_builtin(__builtin_mul_overflow))
64+ return __builtin_mul_overflow(a, b, result);
65+#else
66+ if (firstBitSet(a)+firstBitSet(b)>31) // int is signed, so we can't use 32 bits
67+ return true;
68+ *result = a * b;
69+ return false;
70+#endif
71+}
72+
73+
74 // Compute a linear PCM value from the given differential coded value.
75 static int16_t decodeSample(ms_adpcm_state &state,
76- uint8_t code, const int16_t *coefficient)
77+ uint8_t code, const int16_t *coefficient, bool *ok=NULL)
78 {
79 int linearSample = (state.sample1 * coefficient[0] +
80 state.sample2 * coefficient[1]) >> 8;
81+ int delta;
82
83 linearSample += ((code & 0x08) ? (code - 0x10) : code) * state.delta;
84
85 linearSample = clamp(linearSample, MIN_INT16, MAX_INT16);
86
87- int delta = (state.delta * adaptationTable[code]) >> 8;
88+ if (multiplyCheckOverflow(state.delta, adaptationTable[code], &delta))
89+ {
90+ if (ok) *ok=false;
91+ _af_error(AF_BAD_COMPRESSION, "Error decoding sample");
92+ return 0;
93+ }
94+ delta >>= 8;
95 if (delta < 16)
96 delta = 16;
97
98 state.delta = delta;
99 state.sample2 = state.sample1;
100 state.sample1 = linearSample;
101+ if (ok) *ok=true;
102
103 return static_cast<int16_t>(linearSample);
104 }
105@@ -212,13 +248,16 @@ int MSADPCM::decodeBlock(const uint8_t *encoded, int16_t *decoded)
106 {
107 uint8_t code;
108 int16_t newSample;
109+ bool ok;
110
111 code = *encoded >> 4;
112- newSample = decodeSample(*state[0], code, coefficient[0]);
113+ newSample = decodeSample(*state[0], code, coefficient[0], &ok);
114+ if (!ok) return 0;
115 *decoded++ = newSample;
116
117 code = *encoded & 0x0f;
118- newSample = decodeSample(*state[1], code, coefficient[1]);
119+ newSample = decodeSample(*state[1], code, coefficient[1], &ok);
120+ if (!ok) return 0;
121 *decoded++ = newSample;
122
123 encoded++;
124--
1252.11.0
126