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