|
|
852130 |
diff -Nur audiofile-0.3.6/libaudiofile/modules/BlockCodec.cpp audiofile-0.3.6-pull42/libaudiofile/modules/BlockCodec.cpp
|
|
|
852130 |
--- audiofile-0.3.6/libaudiofile/modules/BlockCodec.cpp 2013-03-06 06:30:03.000000000 +0100
|
|
|
852130 |
+++ audiofile-0.3.6-pull42/libaudiofile/modules/BlockCodec.cpp 2017-03-10 15:40:02.000000000 +0100
|
|
|
852130 |
@@ -52,8 +52,9 @@
|
|
|
852130 |
// Decompress into m_outChunk.
|
|
|
852130 |
for (int i=0; i
|
|
|
852130 |
{
|
|
|
852130 |
- decodeBlock(static_cast<const uint8_t *>(m_inChunk->buffer) + i * m_bytesPerPacket,
|
|
|
852130 |
- static_cast<int16_t *>(m_outChunk->buffer) + i * m_framesPerPacket * m_track->f.channelCount);
|
|
|
852130 |
+ if (decodeBlock(static_cast<const uint8_t *>(m_inChunk->buffer) + i * m_bytesPerPacket,
|
|
|
852130 |
+ static_cast<int16_t *>(m_outChunk->buffer) + i * m_framesPerPacket * m_track->f.channelCount)==0)
|
|
|
852130 |
+ break;
|
|
|
852130 |
|
|
|
852130 |
framesRead += m_framesPerPacket;
|
|
|
852130 |
}
|
|
|
852130 |
diff -Nur audiofile-0.3.6/libaudiofile/modules/MSADPCM.cpp audiofile-0.3.6-pull42/libaudiofile/modules/MSADPCM.cpp
|
|
|
852130 |
--- audiofile-0.3.6/libaudiofile/modules/MSADPCM.cpp 2013-03-06 06:30:03.000000000 +0100
|
|
|
852130 |
+++ audiofile-0.3.6-pull42/libaudiofile/modules/MSADPCM.cpp 2017-03-10 15:40:02.000000000 +0100
|
|
|
852130 |
@@ -101,24 +101,60 @@
|
|
|
852130 |
768, 614, 512, 409, 307, 230, 230, 230
|
|
|
852130 |
};
|
|
|
852130 |
|
|
|
852130 |
+int firstBitSet(int x)
|
|
|
852130 |
+{
|
|
|
852130 |
+ int position=0;
|
|
|
852130 |
+ while (x!=0)
|
|
|
852130 |
+ {
|
|
|
852130 |
+ x>>=1;
|
|
|
852130 |
+ ++position;
|
|
|
852130 |
+ }
|
|
|
852130 |
+ return position;
|
|
|
852130 |
+}
|
|
|
852130 |
+
|
|
|
852130 |
+#ifndef __has_builtin
|
|
|
852130 |
+#define __has_builtin(x) 0
|
|
|
852130 |
+#endif
|
|
|
852130 |
+
|
|
|
852130 |
+bool multiplyCheckOverflow(int a, int b, int *result)
|
|
|
852130 |
+{
|
|
|
852130 |
+#if (defined __GNUC__ && __GNUC__ >= 5) || ( __clang__ && __has_builtin(__builtin_mul_overflow))
|
|
|
852130 |
+ return __builtin_mul_overflow(a, b, result);
|
|
|
852130 |
+#else
|
|
|
852130 |
+ if (firstBitSet(a)+firstBitSet(b)>31) // int is signed, so we can't use 32 bits
|
|
|
852130 |
+ return true;
|
|
|
852130 |
+ *result = a * b;
|
|
|
852130 |
+ return false;
|
|
|
852130 |
+#endif
|
|
|
852130 |
+}
|
|
|
852130 |
+
|
|
|
852130 |
+
|
|
|
852130 |
// Compute a linear PCM value from the given differential coded value.
|
|
|
852130 |
static int16_t decodeSample(ms_adpcm_state &state,
|
|
|
852130 |
- uint8_t code, const int16_t *coefficient)
|
|
|
852130 |
+ uint8_t code, const int16_t *coefficient, bool *ok=NULL)
|
|
|
852130 |
{
|
|
|
852130 |
int linearSample = (state.sample1 * coefficient[0] +
|
|
|
852130 |
state.sample2 * coefficient[1]) >> 8;
|
|
|
852130 |
+ int delta;
|
|
|
852130 |
|
|
|
852130 |
linearSample += ((code & 0x08) ? (code - 0x10) : code) * state.delta;
|
|
|
852130 |
|
|
|
852130 |
linearSample = clamp(linearSample, MIN_INT16, MAX_INT16);
|
|
|
852130 |
|
|
|
852130 |
- int delta = (state.delta * adaptationTable[code]) >> 8;
|
|
|
852130 |
+ if (multiplyCheckOverflow(state.delta, adaptationTable[code], &delta))
|
|
|
852130 |
+ {
|
|
|
852130 |
+ if (ok) *ok=false;
|
|
|
852130 |
+ _af_error(AF_BAD_COMPRESSION, "Error decoding sample");
|
|
|
852130 |
+ return 0;
|
|
|
852130 |
+ }
|
|
|
852130 |
+ delta >>= 8;
|
|
|
852130 |
if (delta < 16)
|
|
|
852130 |
delta = 16;
|
|
|
852130 |
|
|
|
852130 |
state.delta = delta;
|
|
|
852130 |
state.sample2 = state.sample1;
|
|
|
852130 |
state.sample1 = linearSample;
|
|
|
852130 |
+ if (ok) *ok=true;
|
|
|
852130 |
|
|
|
852130 |
return static_cast<int16_t>(linearSample);
|
|
|
852130 |
}
|
|
|
852130 |
@@ -212,13 +248,16 @@
|
|
|
852130 |
{
|
|
|
852130 |
uint8_t code;
|
|
|
852130 |
int16_t newSample;
|
|
|
852130 |
+ bool ok;
|
|
|
852130 |
|
|
|
852130 |
code = *encoded >> 4;
|
|
|
852130 |
- newSample = decodeSample(*state[0], code, coefficient[0]);
|
|
|
852130 |
+ newSample = decodeSample(*state[0], code, coefficient[0], &ok;;
|
|
|
852130 |
+ if (!ok) return 0;
|
|
|
852130 |
*decoded++ = newSample;
|
|
|
852130 |
|
|
|
852130 |
code = *encoded & 0x0f;
|
|
|
852130 |
- newSample = decodeSample(*state[1], code, coefficient[1]);
|
|
|
852130 |
+ newSample = decodeSample(*state[1], code, coefficient[1], &ok;;
|
|
|
852130 |
+ if (!ok) return 0;
|
|
|
852130 |
*decoded++ = newSample;
|
|
|
852130 |
|
|
|
852130 |
encoded++;
|
|
|
852130 |
diff -Nur audiofile-0.3.6/libaudiofile/WAVE.cpp audiofile-0.3.6-pull42/libaudiofile/WAVE.cpp
|
|
|
852130 |
--- audiofile-0.3.6/libaudiofile/WAVE.cpp 2013-03-06 06:30:03.000000000 +0100
|
|
|
852130 |
+++ audiofile-0.3.6-pull42/libaudiofile/WAVE.cpp 2017-03-10 15:40:02.000000000 +0100
|
|
|
852130 |
@@ -281,6 +281,12 @@
|
|
|
852130 |
|
|
|
852130 |
/* numCoefficients should be at least 7. */
|
|
|
852130 |
assert(numCoefficients >= 7 && numCoefficients <= 255);
|
|
|
852130 |
+ if (numCoefficients < 7 || numCoefficients > 255)
|
|
|
852130 |
+ {
|
|
|
852130 |
+ _af_error(AF_BAD_HEADER,
|
|
|
852130 |
+ "Bad number of coefficients");
|
|
|
852130 |
+ return AF_FAIL;
|
|
|
852130 |
+ }
|
|
|
852130 |
|
|
|
852130 |
m_msadpcmNumCoefficients = numCoefficients;
|
|
|
852130 |
|
|
|
852130 |
@@ -834,6 +840,8 @@
|
|
|
852130 |
}
|
|
|
852130 |
|
|
|
852130 |
TrackSetup *track = setup->getTrack();
|
|
|
852130 |
+ if (!track)
|
|
|
852130 |
+ return AF_NULL_FILESETUP;
|
|
|
852130 |
|
|
|
852130 |
if (track->f.isCompressed())
|
|
|
852130 |
{
|
|
|
852130 |
diff -Nur audiofile-0.3.6/sfcommands/sfconvert.c audiofile-0.3.6-pull42/sfcommands/sfconvert.c
|
|
|
852130 |
--- audiofile-0.3.6/sfcommands/sfconvert.c 2013-03-06 06:30:03.000000000 +0100
|
|
|
852130 |
+++ audiofile-0.3.6-pull42/sfcommands/sfconvert.c 2017-03-10 15:40:02.000000000 +0100
|
|
|
852130 |
@@ -45,6 +45,33 @@
|
|
|
852130 |
void usageerror (void);
|
|
|
852130 |
bool copyaudiodata (AFfilehandle infile, AFfilehandle outfile, int trackid);
|
|
|
852130 |
|
|
|
852130 |
+int firstBitSet(int x)
|
|
|
852130 |
+{
|
|
|
852130 |
+ int position=0;
|
|
|
852130 |
+ while (x!=0)
|
|
|
852130 |
+ {
|
|
|
852130 |
+ x>>=1;
|
|
|
852130 |
+ ++position;
|
|
|
852130 |
+ }
|
|
|
852130 |
+ return position;
|
|
|
852130 |
+}
|
|
|
852130 |
+
|
|
|
852130 |
+#ifndef __has_builtin
|
|
|
852130 |
+#define __has_builtin(x) 0
|
|
|
852130 |
+#endif
|
|
|
852130 |
+
|
|
|
852130 |
+bool multiplyCheckOverflow(int a, int b, int *result)
|
|
|
852130 |
+{
|
|
|
852130 |
+#if (defined __GNUC__ && __GNUC__ >= 5) || ( __clang__ && __has_builtin(__builtin_mul_overflow))
|
|
|
852130 |
+ return __builtin_mul_overflow(a, b, result);
|
|
|
852130 |
+#else
|
|
|
852130 |
+ if (firstBitSet(a)+firstBitSet(b)>31) // int is signed, so we can't use 32 bits
|
|
|
852130 |
+ return true;
|
|
|
852130 |
+ *result = a * b;
|
|
|
852130 |
+ return false;
|
|
|
852130 |
+#endif
|
|
|
852130 |
+}
|
|
|
852130 |
+
|
|
|
852130 |
int main (int argc, char **argv)
|
|
|
852130 |
{
|
|
|
852130 |
if (argc == 2)
|
|
|
852130 |
@@ -323,8 +350,11 @@
|
|
|
852130 |
{
|
|
|
852130 |
int frameSize = afGetVirtualFrameSize(infile, trackid, 1);
|
|
|
852130 |
|
|
|
852130 |
- const int kBufferFrameCount = 65536;
|
|
|
852130 |
- void *buffer = malloc(kBufferFrameCount * frameSize);
|
|
|
852130 |
+ int kBufferFrameCount = 65536;
|
|
|
852130 |
+ int bufferSize;
|
|
|
852130 |
+ while (multiplyCheckOverflow(kBufferFrameCount, frameSize, &bufferSize))
|
|
|
852130 |
+ kBufferFrameCount /= 2;
|
|
|
852130 |
+ void *buffer = malloc(bufferSize);
|
|
|
852130 |
|
|
|
852130 |
AFframecount totalFrames = afGetFrameCount(infile, AF_DEFAULT_TRACK);
|
|
|
852130 |
AFframecount totalFramesWritten = 0;
|