mirror of
https://github.com/cookiengineer/audacity
synced 2025-08-02 00:49:33 +02:00
Guard against unusually large numbers of channels in imported .wav file.
This commit is contained in:
parent
f6b89ae80f
commit
407c1dc4b2
@ -53,6 +53,8 @@
|
|||||||
#include "../WaveTrack.h"
|
#include "../WaveTrack.h"
|
||||||
#include "ImportPlugin.h"
|
#include "ImportPlugin.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#ifdef USE_LIBID3TAG
|
#ifdef USE_LIBID3TAG
|
||||||
#include <id3tag.h>
|
#include <id3tag.h>
|
||||||
// DM: the following functions were supposed to have been
|
// DM: the following functions were supposed to have been
|
||||||
@ -413,15 +415,29 @@ int PCMImportFileHandle::Import(TrackFactory *trackFactory,
|
|||||||
// samples from the file and store our own local copy of the
|
// samples from the file and store our own local copy of the
|
||||||
// samples in the tracks.
|
// samples in the tracks.
|
||||||
|
|
||||||
samplePtr srcbuffer = NewSamples(maxBlockSize * mInfo.channels,
|
// PRL: guard against excessive memory buffer allocation in case of many channels
|
||||||
mFormat);
|
__int64 maxBlock = std::min(maxBlockSize,
|
||||||
samplePtr buffer = NewSamples(maxBlockSize, mFormat);
|
__int64(std::numeric_limits<int>::max() /
|
||||||
|
(mInfo.channels * SAMPLE_SIZE(mFormat)))
|
||||||
|
);
|
||||||
|
if (maxBlock < 1)
|
||||||
|
return eProgressFailed;
|
||||||
|
|
||||||
|
samplePtr srcbuffer;
|
||||||
|
while (NULL == (srcbuffer = NewSamples(maxBlock * mInfo.channels, mFormat)))
|
||||||
|
{
|
||||||
|
maxBlock >>= 1;
|
||||||
|
if (maxBlock < 1)
|
||||||
|
return eProgressFailed;
|
||||||
|
}
|
||||||
|
|
||||||
|
samplePtr buffer = NewSamples(maxBlock, mFormat);
|
||||||
|
|
||||||
unsigned long framescompleted = 0;
|
unsigned long framescompleted = 0;
|
||||||
|
|
||||||
long block;
|
long block;
|
||||||
do {
|
do {
|
||||||
block = maxBlockSize;
|
block = maxBlock;
|
||||||
|
|
||||||
if (mFormat == int16Sample)
|
if (mFormat == int16Sample)
|
||||||
block = sf_readf_short(mFile, (short *)srcbuffer, block);
|
block = sf_readf_short(mFile, (short *)srcbuffer, block);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user