From 8515ea12d283632e7d0103286e679542d896058b Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Tue, 10 Nov 2020 17:49:14 +0100 Subject: gnu: audiofile: Shorten patch file names. At least 'audiofile-division-by-zero-BlockCodec-runPull.patch' could end up not being included in a tarball. * gnu/packages/patches/audiofile-Check-the-number-of-coefficients.patch: Rename to... * gnu/packages/patches/audiofile-check-number-of-coefficients.patch: ... this. * gnu/packages/patches/audiofile-division-by-zero-BlockCodec-runPull.patch: Rename to... * gnu/packages/patches/audiofile-division-by-zero.patch: ....this. * gnu/packages/patches/audiofile-signature-of-multiplyCheckOverflow.patch: Rename to... * gnu/packages/patches/audiofile-function-signature.patch: ... this. * gnu/packages/patches/audiofile-Fix-multiply-overflow-sfconvert.patch: Rename to.... * gnu/packages/patches/audiofile-multiply-overflow.patch: ... this. * gnu/packages/patches/audiofile-Fix-overflow-in-MSADPCM-decodeSam.patch: Rename to... * gnu/packages/patches/audiofile-overflow-in-MSADPCM.patch: ... this. * gnu/packages/audio.scm (audiofile)[source]: Adjust accordingly. * gnu/local.mk (dist_patch_DATA): Likewise. --- gnu/local.mk | 12 +-- gnu/packages/audio.scm | 10 +- ...udiofile-Check-the-number-of-coefficients.patch | 30 ------ ...audiofile-Fix-multiply-overflow-sfconvert.patch | 66 ------------ ...diofile-Fix-overflow-in-MSADPCM-decodeSam.patch | 116 --------------------- .../audiofile-check-number-of-coefficients.patch | 30 ++++++ ...ofile-division-by-zero-BlockCodec-runPull.patch | 21 ---- .../patches/audiofile-division-by-zero.patch | 21 ++++ .../patches/audiofile-function-signature.patch | 35 +++++++ .../patches/audiofile-multiply-overflow.patch | 66 ++++++++++++ .../patches/audiofile-overflow-in-MSADPCM.patch | 116 +++++++++++++++++++++ ...iofile-signature-of-multiplyCheckOverflow.patch | 35 ------- 12 files changed, 279 insertions(+), 279 deletions(-) delete mode 100644 gnu/packages/patches/audiofile-Check-the-number-of-coefficients.patch delete mode 100644 gnu/packages/patches/audiofile-Fix-multiply-overflow-sfconvert.patch delete mode 100644 gnu/packages/patches/audiofile-Fix-overflow-in-MSADPCM-decodeSam.patch create mode 100644 gnu/packages/patches/audiofile-check-number-of-coefficients.patch delete mode 100644 gnu/packages/patches/audiofile-division-by-zero-BlockCodec-runPull.patch create mode 100644 gnu/packages/patches/audiofile-division-by-zero.patch create mode 100644 gnu/packages/patches/audiofile-function-signature.patch create mode 100644 gnu/packages/patches/audiofile-multiply-overflow.patch create mode 100644 gnu/packages/patches/audiofile-overflow-in-MSADPCM.patch delete mode 100644 gnu/packages/patches/audiofile-signature-of-multiplyCheckOverflow.patch diff --git a/gnu/local.mk b/gnu/local.mk index 9a8d6dd4d9..d5a13cbdbd 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -800,14 +800,14 @@ dist_patch_DATA = \ %D%/packages/patches/audiofile-CVE-2015-7747.patch \ %D%/packages/patches/audiofile-CVE-2018-13440.patch \ %D%/packages/patches/audiofile-CVE-2018-17095.patch \ - %D%/packages/patches/audiofile-Check-the-number-of-coefficients.patch \ + %D%/packages/patches/audiofile-check-number-of-coefficients.patch \ %D%/packages/patches/audiofile-Fail-on-error-in-parseFormat.patch \ %D%/packages/patches/audiofile-Fix-index-overflow-in-IMA.cpp.patch \ - %D%/packages/patches/audiofile-Fix-multiply-overflow-sfconvert.patch \ - %D%/packages/patches/audiofile-Fix-overflow-in-MSADPCM-decodeSam.patch \ - %D%/packages/patches/audiofile-division-by-zero-BlockCodec-runPull.patch \ - %D%/packages/patches/audiofile-hurd.patch \ - %D%/packages/patches/audiofile-signature-of-multiplyCheckOverflow.patch \ + %D%/packages/patches/audiofile-multiply-overflow.patch \ + %D%/packages/patches/audiofile-overflow-in-MSADPCM.patch \ + %D%/packages/patches/audiofile-division-by-zero.patch \ + %D%/packages/patches/audiofile-hurd.patch \ + %D%/packages/patches/audiofile-function-signature.patch \ %D%/packages/patches/automake-skip-amhello-tests.patch \ %D%/packages/patches/avahi-localstatedir.patch \ %D%/packages/patches/avogadro-boost148.patch \ diff --git a/gnu/packages/audio.scm b/gnu/packages/audio.scm index 6479398cb5..6733c8d212 100644 --- a/gnu/packages/audio.scm +++ b/gnu/packages/audio.scm @@ -862,16 +862,16 @@ tools.") "audiofile-Fix-index-overflow-in-IMA.cpp.patch" ;; CVE-2017-6827, CVE-2017-6828, CVE-2017-6832, CVE-2017-6835, ;; CVE-2017-6837: - "audiofile-Check-the-number-of-coefficients.patch" + "audiofile-check-number-of-coefficients.patch" ;; CVE-2017-6839: - "audiofile-Fix-overflow-in-MSADPCM-decodeSam.patch" + "audiofile-overflow-in-MSADPCM.patch" ;; CVE-2017-6830, CVE-2017-6834, CVE-2017-6836, CVE-2017-6838: - "audiofile-Fix-multiply-overflow-sfconvert.patch" - "audiofile-signature-of-multiplyCheckOverflow.patch" + "audiofile-multiply-overflow.patch" + "audiofile-function-signature.patch" ;; CVE-2017-6831: "audiofile-Fail-on-error-in-parseFormat.patch" ;; CVE-2017-6833: - "audiofile-division-by-zero-BlockCodec-runPull.patch" + "audiofile-division-by-zero.patch" "audiofile-CVE-2018-13440.patch" "audiofile-CVE-2018-17095.patch")))) (properties `((lint-hidden-cve . ("CVE-2017-6829" diff --git a/gnu/packages/patches/audiofile-Check-the-number-of-coefficients.patch b/gnu/packages/patches/audiofile-Check-the-number-of-coefficients.patch deleted file mode 100644 index f9427cbe61..0000000000 --- a/gnu/packages/patches/audiofile-Check-the-number-of-coefficients.patch +++ /dev/null @@ -1,30 +0,0 @@ -From: Antonio Larrosa -Date: Mon, 6 Mar 2017 12:51:22 +0100 -Subject: Always check the number of coefficients - -When building the library with NDEBUG, asserts are eliminated -so it's better to always check that the number of coefficients -is inside the array range. - -This fixes the 00191-audiofile-indexoob issue in #41 ---- - libaudiofile/WAVE.cpp | 6 ++++++ - 1 file changed, 6 insertions(+) - -diff --git a/libaudiofile/WAVE.cpp b/libaudiofile/WAVE.cpp -index 9dd8511..0fc48e8 100644 ---- a/libaudiofile/WAVE.cpp -+++ b/libaudiofile/WAVE.cpp -@@ -281,6 +281,12 @@ status WAVEFile::parseFormat(const Tag &id, uint32_t size) - - /* numCoefficients should be at least 7. */ - assert(numCoefficients >= 7 && numCoefficients <= 255); -+ if (numCoefficients < 7 || numCoefficients > 255) -+ { -+ _af_error(AF_BAD_HEADER, -+ "Bad number of coefficients"); -+ return AF_FAIL; -+ } - - m_msadpcmNumCoefficients = numCoefficients; - diff --git a/gnu/packages/patches/audiofile-Fix-multiply-overflow-sfconvert.patch b/gnu/packages/patches/audiofile-Fix-multiply-overflow-sfconvert.patch deleted file mode 100644 index 0f17140d6b..0000000000 --- a/gnu/packages/patches/audiofile-Fix-multiply-overflow-sfconvert.patch +++ /dev/null @@ -1,66 +0,0 @@ -From: Antonio Larrosa -Date: Mon, 6 Mar 2017 13:54:52 +0100 -Subject: Check for multiplication overflow in sfconvert - -Checks that a multiplication doesn't overflow when -calculating the buffer size, and if it overflows, -reduce the buffer size instead of failing. - -This fixes the 00192-audiofile-signintoverflow-sfconvert case -in #41 ---- - sfcommands/sfconvert.c | 34 ++++++++++++++++++++++++++++++++-- - 1 file changed, 32 insertions(+), 2 deletions(-) - -diff --git a/sfcommands/sfconvert.c b/sfcommands/sfconvert.c -index 80a1bc4..970a3e4 100644 ---- a/sfcommands/sfconvert.c -+++ b/sfcommands/sfconvert.c -@@ -45,6 +45,33 @@ void printusage (void); - void usageerror (void); - bool copyaudiodata (AFfilehandle infile, AFfilehandle outfile, int trackid); - -+int firstBitSet(int x) -+{ -+ int position=0; -+ while (x!=0) -+ { -+ x>>=1; -+ ++position; -+ } -+ return position; -+} -+ -+#ifndef __has_builtin -+#define __has_builtin(x) 0 -+#endif -+ -+int multiplyCheckOverflow(int a, int b, int *result) -+{ -+#if (defined __GNUC__ && __GNUC__ >= 5) || ( __clang__ && __has_builtin(__builtin_mul_overflow)) -+ return __builtin_mul_overflow(a, b, result); -+#else -+ if (firstBitSet(a)+firstBitSet(b)>31) // int is signed, so we can't use 32 bits -+ return true; -+ *result = a * b; -+ return false; -+#endif -+} -+ - int main (int argc, char **argv) - { - if (argc == 2) -@@ -323,8 +350,11 @@ bool copyaudiodata (AFfilehandle infile, AFfilehandle outfile, int trackid) - { - int frameSize = afGetVirtualFrameSize(infile, trackid, 1); - -- const int kBufferFrameCount = 65536; -- void *buffer = malloc(kBufferFrameCount * frameSize); -+ int kBufferFrameCount = 65536; -+ int bufferSize; -+ while (multiplyCheckOverflow(kBufferFrameCount, frameSize, &bufferSize)) -+ kBufferFrameCount /= 2; -+ void *buffer = malloc(bufferSize); - - AFframecount totalFrames = afGetFrameCount(infile, AF_DEFAULT_TRACK); - AFframecount totalFramesWritten = 0; diff --git a/gnu/packages/patches/audiofile-Fix-overflow-in-MSADPCM-decodeSam.patch b/gnu/packages/patches/audiofile-Fix-overflow-in-MSADPCM-decodeSam.patch deleted file mode 100644 index 2be930b924..0000000000 --- a/gnu/packages/patches/audiofile-Fix-overflow-in-MSADPCM-decodeSam.patch +++ /dev/null @@ -1,116 +0,0 @@ -From: Antonio Larrosa -Date: Mon, 6 Mar 2017 13:43:53 +0100 -Subject: Check for multiplication overflow in MSADPCM decodeSample - -Check for multiplication overflow (using __builtin_mul_overflow -if available) in MSADPCM.cpp decodeSample and return an empty -decoded block if an error occurs. - -This fixes the 00193-audiofile-signintoverflow-MSADPCM case of #41 ---- - libaudiofile/modules/BlockCodec.cpp | 5 ++-- - libaudiofile/modules/MSADPCM.cpp | 47 +++++++++++++++++++++++++++++++++---- - 2 files changed, 46 insertions(+), 6 deletions(-) - -diff --git a/libaudiofile/modules/BlockCodec.cpp b/libaudiofile/modules/BlockCodec.cpp -index 45925e8..4731be1 100644 ---- a/libaudiofile/modules/BlockCodec.cpp -+++ b/libaudiofile/modules/BlockCodec.cpp -@@ -52,8 +52,9 @@ void BlockCodec::runPull() - // Decompress into m_outChunk. - for (int i=0; i(m_inChunk->buffer) + i * m_bytesPerPacket, -- static_cast(m_outChunk->buffer) + i * m_framesPerPacket * m_track->f.channelCount); -+ if (decodeBlock(static_cast(m_inChunk->buffer) + i * m_bytesPerPacket, -+ static_cast(m_outChunk->buffer) + i * m_framesPerPacket * m_track->f.channelCount)==0) -+ break; - - framesRead += m_framesPerPacket; - } -diff --git a/libaudiofile/modules/MSADPCM.cpp b/libaudiofile/modules/MSADPCM.cpp -index 8ea3c85..ef9c38c 100644 ---- a/libaudiofile/modules/MSADPCM.cpp -+++ b/libaudiofile/modules/MSADPCM.cpp -@@ -101,24 +101,60 @@ static const int16_t adaptationTable[] = - 768, 614, 512, 409, 307, 230, 230, 230 - }; - -+int firstBitSet(int x) -+{ -+ int position=0; -+ while (x!=0) -+ { -+ x>>=1; -+ ++position; -+ } -+ return position; -+} -+ -+#ifndef __has_builtin -+#define __has_builtin(x) 0 -+#endif -+ -+int multiplyCheckOverflow(int a, int b, int *result) -+{ -+#if (defined __GNUC__ && __GNUC__ >= 5) || ( __clang__ && __has_builtin(__builtin_mul_overflow)) -+ return __builtin_mul_overflow(a, b, result); -+#else -+ if (firstBitSet(a)+firstBitSet(b)>31) // int is signed, so we can't use 32 bits -+ return true; -+ *result = a * b; -+ return false; -+#endif -+} -+ -+ - // Compute a linear PCM value from the given differential coded value. - static int16_t decodeSample(ms_adpcm_state &state, -- uint8_t code, const int16_t *coefficient) -+ uint8_t code, const int16_t *coefficient, bool *ok=NULL) - { - int linearSample = (state.sample1 * coefficient[0] + - state.sample2 * coefficient[1]) >> 8; -+ int delta; - - linearSample += ((code & 0x08) ? (code - 0x10) : code) * state.delta; - - linearSample = clamp(linearSample, MIN_INT16, MAX_INT16); - -- int delta = (state.delta * adaptationTable[code]) >> 8; -+ if (multiplyCheckOverflow(state.delta, adaptationTable[code], &delta)) -+ { -+ if (ok) *ok=false; -+ _af_error(AF_BAD_COMPRESSION, "Error decoding sample"); -+ return 0; -+ } -+ delta >>= 8; - if (delta < 16) - delta = 16; - - state.delta = delta; - state.sample2 = state.sample1; - state.sample1 = linearSample; -+ if (ok) *ok=true; - - return static_cast(linearSample); - } -@@ -212,13 +248,16 @@ int MSADPCM::decodeBlock(const uint8_t *encoded, int16_t *decoded) - { - uint8_t code; - int16_t newSample; -+ bool ok; - - code = *encoded >> 4; -- newSample = decodeSample(*state[0], code, coefficient[0]); -+ newSample = decodeSample(*state[0], code, coefficient[0], &ok); -+ if (!ok) return 0; - *decoded++ = newSample; - - code = *encoded & 0x0f; -- newSample = decodeSample(*state[1], code, coefficient[1]); -+ newSample = decodeSample(*state[1], code, coefficient[1], &ok); -+ if (!ok) return 0; - *decoded++ = newSample; - - encoded++; diff --git a/gnu/packages/patches/audiofile-check-number-of-coefficients.patch b/gnu/packages/patches/audiofile-check-number-of-coefficients.patch new file mode 100644 index 0000000000..f9427cbe61 --- /dev/null +++ b/gnu/packages/patches/audiofile-check-number-of-coefficients.patch @@ -0,0 +1,30 @@ +From: Antonio Larrosa +Date: Mon, 6 Mar 2017 12:51:22 +0100 +Subject: Always check the number of coefficients + +When building the library with NDEBUG, asserts are eliminated +so it's better to always check that the number of coefficients +is inside the array range. + +This fixes the 00191-audiofile-indexoob issue in #41 +--- + libaudiofile/WAVE.cpp | 6 ++++++ + 1 file changed, 6 insertions(+) + +diff --git a/libaudiofile/WAVE.cpp b/libaudiofile/WAVE.cpp +index 9dd8511..0fc48e8 100644 +--- a/libaudiofile/WAVE.cpp ++++ b/libaudiofile/WAVE.cpp +@@ -281,6 +281,12 @@ status WAVEFile::parseFormat(const Tag &id, uint32_t size) + + /* numCoefficients should be at least 7. */ + assert(numCoefficients >= 7 && numCoefficients <= 255); ++ if (numCoefficients < 7 || numCoefficients > 255) ++ { ++ _af_error(AF_BAD_HEADER, ++ "Bad number of coefficients"); ++ return AF_FAIL; ++ } + + m_msadpcmNumCoefficients = numCoefficients; + diff --git a/gnu/packages/patches/audiofile-division-by-zero-BlockCodec-runPull.patch b/gnu/packages/patches/audiofile-division-by-zero-BlockCodec-runPull.patch deleted file mode 100644 index e001133916..0000000000 --- a/gnu/packages/patches/audiofile-division-by-zero-BlockCodec-runPull.patch +++ /dev/null @@ -1,21 +0,0 @@ -From: Antonio Larrosa -Date: Thu, 9 Mar 2017 10:21:18 +0100 -Subject: Check for division by zero in BlockCodec::runPull - ---- - libaudiofile/modules/BlockCodec.cpp | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/libaudiofile/modules/BlockCodec.cpp b/libaudiofile/modules/BlockCodec.cpp -index 4731be1..eb2fb4d 100644 ---- a/libaudiofile/modules/BlockCodec.cpp -+++ b/libaudiofile/modules/BlockCodec.cpp -@@ -47,7 +47,7 @@ void BlockCodec::runPull() - - // Read the compressed data. - ssize_t bytesRead = read(m_inChunk->buffer, m_bytesPerPacket * blockCount); -- int blocksRead = bytesRead >= 0 ? bytesRead / m_bytesPerPacket : 0; -+ int blocksRead = (bytesRead >= 0 && m_bytesPerPacket > 0) ? bytesRead / m_bytesPerPacket : 0; - - // Decompress into m_outChunk. - for (int i=0; i +Date: Thu, 9 Mar 2017 10:21:18 +0100 +Subject: Check for division by zero in BlockCodec::runPull + +--- + libaudiofile/modules/BlockCodec.cpp | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/libaudiofile/modules/BlockCodec.cpp b/libaudiofile/modules/BlockCodec.cpp +index 4731be1..eb2fb4d 100644 +--- a/libaudiofile/modules/BlockCodec.cpp ++++ b/libaudiofile/modules/BlockCodec.cpp +@@ -47,7 +47,7 @@ void BlockCodec::runPull() + + // Read the compressed data. + ssize_t bytesRead = read(m_inChunk->buffer, m_bytesPerPacket * blockCount); +- int blocksRead = bytesRead >= 0 ? bytesRead / m_bytesPerPacket : 0; ++ int blocksRead = (bytesRead >= 0 && m_bytesPerPacket > 0) ? bytesRead / m_bytesPerPacket : 0; + + // Decompress into m_outChunk. + for (int i=0; i +Date: Fri, 10 Mar 2017 15:40:02 +0100 +Subject: Fix signature of multiplyCheckOverflow. It returns a bool, not an int + +--- + libaudiofile/modules/MSADPCM.cpp | 2 +- + sfcommands/sfconvert.c | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/libaudiofile/modules/MSADPCM.cpp b/libaudiofile/modules/MSADPCM.cpp +index ef9c38c..d8c9553 100644 +--- a/libaudiofile/modules/MSADPCM.cpp ++++ b/libaudiofile/modules/MSADPCM.cpp +@@ -116,7 +116,7 @@ int firstBitSet(int x) + #define __has_builtin(x) 0 + #endif + +-int multiplyCheckOverflow(int a, int b, int *result) ++bool multiplyCheckOverflow(int a, int b, int *result) + { + #if (defined __GNUC__ && __GNUC__ >= 5) || ( __clang__ && __has_builtin(__builtin_mul_overflow)) + return __builtin_mul_overflow(a, b, result); +diff --git a/sfcommands/sfconvert.c b/sfcommands/sfconvert.c +index 970a3e4..367f7a5 100644 +--- a/sfcommands/sfconvert.c ++++ b/sfcommands/sfconvert.c +@@ -60,7 +60,7 @@ int firstBitSet(int x) + #define __has_builtin(x) 0 + #endif + +-int multiplyCheckOverflow(int a, int b, int *result) ++bool multiplyCheckOverflow(int a, int b, int *result) + { + #if (defined __GNUC__ && __GNUC__ >= 5) || ( __clang__ && __has_builtin(__builtin_mul_overflow)) + return __builtin_mul_overflow(a, b, result); diff --git a/gnu/packages/patches/audiofile-multiply-overflow.patch b/gnu/packages/patches/audiofile-multiply-overflow.patch new file mode 100644 index 0000000000..0f17140d6b --- /dev/null +++ b/gnu/packages/patches/audiofile-multiply-overflow.patch @@ -0,0 +1,66 @@ +From: Antonio Larrosa +Date: Mon, 6 Mar 2017 13:54:52 +0100 +Subject: Check for multiplication overflow in sfconvert + +Checks that a multiplication doesn't overflow when +calculating the buffer size, and if it overflows, +reduce the buffer size instead of failing. + +This fixes the 00192-audiofile-signintoverflow-sfconvert case +in #41 +--- + sfcommands/sfconvert.c | 34 ++++++++++++++++++++++++++++++++-- + 1 file changed, 32 insertions(+), 2 deletions(-) + +diff --git a/sfcommands/sfconvert.c b/sfcommands/sfconvert.c +index 80a1bc4..970a3e4 100644 +--- a/sfcommands/sfconvert.c ++++ b/sfcommands/sfconvert.c +@@ -45,6 +45,33 @@ void printusage (void); + void usageerror (void); + bool copyaudiodata (AFfilehandle infile, AFfilehandle outfile, int trackid); + ++int firstBitSet(int x) ++{ ++ int position=0; ++ while (x!=0) ++ { ++ x>>=1; ++ ++position; ++ } ++ return position; ++} ++ ++#ifndef __has_builtin ++#define __has_builtin(x) 0 ++#endif ++ ++int multiplyCheckOverflow(int a, int b, int *result) ++{ ++#if (defined __GNUC__ && __GNUC__ >= 5) || ( __clang__ && __has_builtin(__builtin_mul_overflow)) ++ return __builtin_mul_overflow(a, b, result); ++#else ++ if (firstBitSet(a)+firstBitSet(b)>31) // int is signed, so we can't use 32 bits ++ return true; ++ *result = a * b; ++ return false; ++#endif ++} ++ + int main (int argc, char **argv) + { + if (argc == 2) +@@ -323,8 +350,11 @@ bool copyaudiodata (AFfilehandle infile, AFfilehandle outfile, int trackid) + { + int frameSize = afGetVirtualFrameSize(infile, trackid, 1); + +- const int kBufferFrameCount = 65536; +- void *buffer = malloc(kBufferFrameCount * frameSize); ++ int kBufferFrameCount = 65536; ++ int bufferSize; ++ while (multiplyCheckOverflow(kBufferFrameCount, frameSize, &bufferSize)) ++ kBufferFrameCount /= 2; ++ void *buffer = malloc(bufferSize); + + AFframecount totalFrames = afGetFrameCount(infile, AF_DEFAULT_TRACK); + AFframecount totalFramesWritten = 0; diff --git a/gnu/packages/patches/audiofile-overflow-in-MSADPCM.patch b/gnu/packages/patches/audiofile-overflow-in-MSADPCM.patch new file mode 100644 index 0000000000..2be930b924 --- /dev/null +++ b/gnu/packages/patches/audiofile-overflow-in-MSADPCM.patch @@ -0,0 +1,116 @@ +From: Antonio Larrosa +Date: Mon, 6 Mar 2017 13:43:53 +0100 +Subject: Check for multiplication overflow in MSADPCM decodeSample + +Check for multiplication overflow (using __builtin_mul_overflow +if available) in MSADPCM.cpp decodeSample and return an empty +decoded block if an error occurs. + +This fixes the 00193-audiofile-signintoverflow-MSADPCM case of #41 +--- + libaudiofile/modules/BlockCodec.cpp | 5 ++-- + libaudiofile/modules/MSADPCM.cpp | 47 +++++++++++++++++++++++++++++++++---- + 2 files changed, 46 insertions(+), 6 deletions(-) + +diff --git a/libaudiofile/modules/BlockCodec.cpp b/libaudiofile/modules/BlockCodec.cpp +index 45925e8..4731be1 100644 +--- a/libaudiofile/modules/BlockCodec.cpp ++++ b/libaudiofile/modules/BlockCodec.cpp +@@ -52,8 +52,9 @@ void BlockCodec::runPull() + // Decompress into m_outChunk. + for (int i=0; i(m_inChunk->buffer) + i * m_bytesPerPacket, +- static_cast(m_outChunk->buffer) + i * m_framesPerPacket * m_track->f.channelCount); ++ if (decodeBlock(static_cast(m_inChunk->buffer) + i * m_bytesPerPacket, ++ static_cast(m_outChunk->buffer) + i * m_framesPerPacket * m_track->f.channelCount)==0) ++ break; + + framesRead += m_framesPerPacket; + } +diff --git a/libaudiofile/modules/MSADPCM.cpp b/libaudiofile/modules/MSADPCM.cpp +index 8ea3c85..ef9c38c 100644 +--- a/libaudiofile/modules/MSADPCM.cpp ++++ b/libaudiofile/modules/MSADPCM.cpp +@@ -101,24 +101,60 @@ static const int16_t adaptationTable[] = + 768, 614, 512, 409, 307, 230, 230, 230 + }; + ++int firstBitSet(int x) ++{ ++ int position=0; ++ while (x!=0) ++ { ++ x>>=1; ++ ++position; ++ } ++ return position; ++} ++ ++#ifndef __has_builtin ++#define __has_builtin(x) 0 ++#endif ++ ++int multiplyCheckOverflow(int a, int b, int *result) ++{ ++#if (defined __GNUC__ && __GNUC__ >= 5) || ( __clang__ && __has_builtin(__builtin_mul_overflow)) ++ return __builtin_mul_overflow(a, b, result); ++#else ++ if (firstBitSet(a)+firstBitSet(b)>31) // int is signed, so we can't use 32 bits ++ return true; ++ *result = a * b; ++ return false; ++#endif ++} ++ ++ + // Compute a linear PCM value from the given differential coded value. + static int16_t decodeSample(ms_adpcm_state &state, +- uint8_t code, const int16_t *coefficient) ++ uint8_t code, const int16_t *coefficient, bool *ok=NULL) + { + int linearSample = (state.sample1 * coefficient[0] + + state.sample2 * coefficient[1]) >> 8; ++ int delta; + + linearSample += ((code & 0x08) ? (code - 0x10) : code) * state.delta; + + linearSample = clamp(linearSample, MIN_INT16, MAX_INT16); + +- int delta = (state.delta * adaptationTable[code]) >> 8; ++ if (multiplyCheckOverflow(state.delta, adaptationTable[code], &delta)) ++ { ++ if (ok) *ok=false; ++ _af_error(AF_BAD_COMPRESSION, "Error decoding sample"); ++ return 0; ++ } ++ delta >>= 8; + if (delta < 16) + delta = 16; + + state.delta = delta; + state.sample2 = state.sample1; + state.sample1 = linearSample; ++ if (ok) *ok=true; + + return static_cast(linearSample); + } +@@ -212,13 +248,16 @@ int MSADPCM::decodeBlock(const uint8_t *encoded, int16_t *decoded) + { + uint8_t code; + int16_t newSample; ++ bool ok; + + code = *encoded >> 4; +- newSample = decodeSample(*state[0], code, coefficient[0]); ++ newSample = decodeSample(*state[0], code, coefficient[0], &ok); ++ if (!ok) return 0; + *decoded++ = newSample; + + code = *encoded & 0x0f; +- newSample = decodeSample(*state[1], code, coefficient[1]); ++ newSample = decodeSample(*state[1], code, coefficient[1], &ok); ++ if (!ok) return 0; + *decoded++ = newSample; + + encoded++; diff --git a/gnu/packages/patches/audiofile-signature-of-multiplyCheckOverflow.patch b/gnu/packages/patches/audiofile-signature-of-multiplyCheckOverflow.patch deleted file mode 100644 index 35627d3869..0000000000 --- a/gnu/packages/patches/audiofile-signature-of-multiplyCheckOverflow.patch +++ /dev/null @@ -1,35 +0,0 @@ -From: Antonio Larrosa -Date: Fri, 10 Mar 2017 15:40:02 +0100 -Subject: Fix signature of multiplyCheckOverflow. It returns a bool, not an int - ---- - libaudiofile/modules/MSADPCM.cpp | 2 +- - sfcommands/sfconvert.c | 2 +- - 2 files changed, 2 insertions(+), 2 deletions(-) - -diff --git a/libaudiofile/modules/MSADPCM.cpp b/libaudiofile/modules/MSADPCM.cpp -index ef9c38c..d8c9553 100644 ---- a/libaudiofile/modules/MSADPCM.cpp -+++ b/libaudiofile/modules/MSADPCM.cpp -@@ -116,7 +116,7 @@ int firstBitSet(int x) - #define __has_builtin(x) 0 - #endif - --int multiplyCheckOverflow(int a, int b, int *result) -+bool multiplyCheckOverflow(int a, int b, int *result) - { - #if (defined __GNUC__ && __GNUC__ >= 5) || ( __clang__ && __has_builtin(__builtin_mul_overflow)) - return __builtin_mul_overflow(a, b, result); -diff --git a/sfcommands/sfconvert.c b/sfcommands/sfconvert.c -index 970a3e4..367f7a5 100644 ---- a/sfcommands/sfconvert.c -+++ b/sfcommands/sfconvert.c -@@ -60,7 +60,7 @@ int firstBitSet(int x) - #define __has_builtin(x) 0 - #endif - --int multiplyCheckOverflow(int a, int b, int *result) -+bool multiplyCheckOverflow(int a, int b, int *result) - { - #if (defined __GNUC__ && __GNUC__ >= 5) || ( __clang__ && __has_builtin(__builtin_mul_overflow)) - return __builtin_mul_overflow(a, b, result); -- cgit v1.2.3