• Skip to sidebar navigation
  • Skip to content

Bitbucket

  • More
    ProjectsRepositories
  • Help
    • Online help
    • Learn Git
    • Welcome to Bitbucket
    • Keyboard shortcuts
  • Log In
Alexander Dahl
  1. Alexander Dahl

buildroot

Public
Actions
  • Clone
  • Compare

Learn more about cloning repositories

You have read-only access

Navigation
  • Source
  • Commits
  • Branches
  • All Branches Graph
  • Forks
  1. Alexander Dahl
  2. buildroot

Source

buildroot/package/audiofile/0007-Check-for-multiplication-overflow-in-MSADPCM-decodeS.patch
Peter KorsgaardPeter Korsgaard committed 844a7c6281e30 Mar 2017
Raw file
Source viewDiff to previous
xxxxxxxxxx
 
1
From beacc44eb8cdf6d58717ec1a5103c5141f1b37f9 Mon Sep 17 00:00:00 2001
2
From: Antonio Larrosa <larrosa@kde.org>
3
Date: Mon, 6 Mar 2017 13:43:53 +0100
4
Subject: [PATCH] Check for multiplication overflow in MSADPCM decodeSample
5
​
6
Check for multiplication overflow (using __builtin_mul_overflow
7
if available) in MSADPCM.cpp decodeSample and return an empty
8
decoded block if an error occurs.
9
​
10
This fixes the 00193-audiofile-signintoverflow-MSADPCM case of #41
11
​
12
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
13
---
14
 libaudiofile/modules/BlockCodec.cpp |  5 ++--
15
 libaudiofile/modules/MSADPCM.cpp    | 47 +++++++++++++++++++++++++++++++++----
16
 2 files changed, 46 insertions(+), 6 deletions(-)
17
​
18
diff --git a/libaudiofile/modules/BlockCodec.cpp b/libaudiofile/modules/BlockCodec.cpp
19
index 45925e8..4731be1 100644
20
--- a/libaudiofile/modules/BlockCodec.cpp
21
+++ b/libaudiofile/modules/BlockCodec.cpp
22
@@ -52,8 +52,9 @@ void BlockCodec::runPull()
23
    // Decompress into m_outChunk.
24
    for (int i=0; i<blocksRead; i++)
25
    {
26
-       decodeBlock(static_cast<const uint8_t *>(m_inChunk->buffer) + i * m_bytesPerPacket,
27
-           static_cast<int16_t *>(m_outChunk->buffer) + i * m_framesPerPacket * m_track->f.channelCount);
28
+       if (decodeBlock(static_cast<const uint8_t *>(m_inChunk->buffer) + i * m_bytesPerPacket,
29
+           static_cast<int16_t *>(m_outChunk->buffer) + i * m_framesPerPacket * m_track->f.channelCount)==0)
30
+           break;
31
 
32
        framesRead += m_framesPerPacket;
33
    }
34
diff --git a/libaudiofile/modules/MSADPCM.cpp b/libaudiofile/modules/MSADPCM.cpp
35
index 8ea3c85..ef9c38c 100644
36
--- a/libaudiofile/modules/MSADPCM.cpp
37
+++ b/libaudiofile/modules/MSADPCM.cpp
38
@@ -101,24 +101,60 @@ static const int16_t adaptationTable[] =
39
    768, 614, 512, 409, 307, 230, 230, 230
40
 };
41
 
42
+int firstBitSet(int x)
43
+{
44
+        int position=0;
45
+        while (x!=0)
46
+        {
47
+                x>>=1;
48
+                ++position;
49
+        }
50
+        return position;
51
+}
52
+
53
+#ifndef __has_builtin
54
+#define __has_builtin(x) 0
55
+#endif
56
+
57
+int multiplyCheckOverflow(int a, int b, int *result)
58
+{
59
+#if (defined __GNUC__ && __GNUC__ >= 5) || ( __clang__ && __has_builtin(__builtin_mul_overflow))
60
+   return __builtin_mul_overflow(a, b, result);
61
+#else
62
+   if (firstBitSet(a)+firstBitSet(b)>31) // int is signed, so we can't use 32 bits
63
+       return true;
64
+   *result = a * b;
65
+   return false;
66
+#endif
67
+}
68
+
69
+
70
 // Compute a linear PCM value from the given differential coded value.
71
 static int16_t decodeSample(ms_adpcm_state &state,
72
-   uint8_t code, const int16_t *coefficient)
73
+   uint8_t code, const int16_t *coefficient, bool *ok=NULL)
74
 {
75
    int linearSample = (state.sample1 * coefficient[0] +
76
        state.sample2 * coefficient[1]) >> 8;
77
+   int delta;
78
 
79
    linearSample += ((code & 0x08) ? (code - 0x10) : code) * state.delta;
80
 
81
    linearSample = clamp(linearSample, MIN_INT16, MAX_INT16);
82
 
83
-   int delta = (state.delta * adaptationTable[code]) >> 8;
84
+   if (multiplyCheckOverflow(state.delta, adaptationTable[code], &delta))
85
+   {
86
+                if (ok) *ok=false;
87
+       _af_error(AF_BAD_COMPRESSION, "Error decoding sample");
88
+       return 0;
89
+   }
90
+   delta >>= 8;
91
    if (delta < 16)
92
        delta = 16;
  • Git repository management for enterprise teams powered by Atlassian Bitbucket
  • Atlassian Bitbucket v6.7.2
  • Documentation
  • Request a feature
  • About
  • Contact Atlassian
Atlassian

Everything looks good. We'll let you know here if there's anything you should know about.