зеркало из https://github.com/mozilla/gecko-dev.git
bug 1201855 use unsigned integers for buffer positions so that negative buffer positions are impossible r=padenot
I think the limits on sample rates already ensure that mBufferPosition will not overflow, but this makes sure that there are no out of bounds reads. The node checks the parameters are > 0 before sending to the engine. --HG-- extra : rebase_source : 3547c7a6ed8bd1e30a34c8c402a1c339ecb89ac2
This commit is contained in:
Родитель
129da4defa
Коммит
f0c5e3a312
|
@ -113,14 +113,24 @@ public:
|
||||||
switch (aIndex) {
|
switch (aIndex) {
|
||||||
case AudioBufferSourceNode::SAMPLE_RATE: mBufferSampleRate = aParam; break;
|
case AudioBufferSourceNode::SAMPLE_RATE: mBufferSampleRate = aParam; break;
|
||||||
case AudioBufferSourceNode::BUFFERSTART:
|
case AudioBufferSourceNode::BUFFERSTART:
|
||||||
|
MOZ_ASSERT(aParam >= 0);
|
||||||
if (mBufferPosition == 0) {
|
if (mBufferPosition == 0) {
|
||||||
mBufferPosition = aParam;
|
mBufferPosition = aParam;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case AudioBufferSourceNode::BUFFEREND: mBufferEnd = aParam; break;
|
case AudioBufferSourceNode::BUFFEREND:
|
||||||
|
MOZ_ASSERT(aParam >= 0);
|
||||||
|
mBufferEnd = aParam;
|
||||||
|
break;
|
||||||
case AudioBufferSourceNode::LOOP: mLoop = !!aParam; break;
|
case AudioBufferSourceNode::LOOP: mLoop = !!aParam; break;
|
||||||
case AudioBufferSourceNode::LOOPSTART: mLoopStart = aParam; break;
|
case AudioBufferSourceNode::LOOPSTART:
|
||||||
case AudioBufferSourceNode::LOOPEND: mLoopEnd = aParam; break;
|
MOZ_ASSERT(aParam >= 0);
|
||||||
|
mLoopStart = aParam;
|
||||||
|
break;
|
||||||
|
case AudioBufferSourceNode::LOOPEND:
|
||||||
|
MOZ_ASSERT(aParam >= 0);
|
||||||
|
mLoopEnd = aParam;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
NS_ERROR("Bad AudioBufferSourceNodeEngine Int32Parameter");
|
NS_ERROR("Bad AudioBufferSourceNodeEngine Int32Parameter");
|
||||||
}
|
}
|
||||||
|
@ -227,7 +237,7 @@ public:
|
||||||
uint32_t* aOffsetWithinBlock,
|
uint32_t* aOffsetWithinBlock,
|
||||||
uint32_t aAvailableInOutput,
|
uint32_t aAvailableInOutput,
|
||||||
StreamTime* aCurrentPosition,
|
StreamTime* aCurrentPosition,
|
||||||
int32_t aBufferMax)
|
uint32_t aBufferMax)
|
||||||
{
|
{
|
||||||
if (*aOffsetWithinBlock == 0) {
|
if (*aOffsetWithinBlock == 0) {
|
||||||
aOutput->AllocateChannels(aChannels);
|
aOutput->AllocateChannels(aChannels);
|
||||||
|
@ -305,8 +315,8 @@ public:
|
||||||
static_cast<AudioDataValue*>(nullptr), &inSamples,
|
static_cast<AudioDataValue*>(nullptr), &inSamples,
|
||||||
outputData, &outSamples);
|
outputData, &outSamples);
|
||||||
if (++i == aChannels) {
|
if (++i == aChannels) {
|
||||||
|
MOZ_ASSERT(inSamples <= mRemainingResamplerTail);
|
||||||
mRemainingResamplerTail -= inSamples;
|
mRemainingResamplerTail -= inSamples;
|
||||||
MOZ_ASSERT(mRemainingResamplerTail >= 0);
|
|
||||||
*aOffsetWithinBlock += outSamples;
|
*aOffsetWithinBlock += outSamples;
|
||||||
*aCurrentPosition += outSamples;
|
*aCurrentPosition += outSamples;
|
||||||
break;
|
break;
|
||||||
|
@ -359,7 +369,7 @@ public:
|
||||||
uint32_t aChannels,
|
uint32_t aChannels,
|
||||||
uint32_t* aOffsetWithinBlock,
|
uint32_t* aOffsetWithinBlock,
|
||||||
StreamTime* aCurrentPosition,
|
StreamTime* aCurrentPosition,
|
||||||
int32_t aBufferMax)
|
uint32_t aBufferMax)
|
||||||
{
|
{
|
||||||
MOZ_ASSERT(*aCurrentPosition < mStop);
|
MOZ_ASSERT(*aCurrentPosition < mStop);
|
||||||
uint32_t availableInOutput =
|
uint32_t availableInOutput =
|
||||||
|
@ -392,8 +402,8 @@ public:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t numFrames = std::min<uint32_t>(aBufferMax - mBufferPosition,
|
uint32_t numFrames = std::min(aBufferMax - mBufferPosition,
|
||||||
availableInOutput);
|
availableInOutput);
|
||||||
if (numFrames == WEBAUDIO_BLOCK_SIZE) {
|
if (numFrames == WEBAUDIO_BLOCK_SIZE) {
|
||||||
MOZ_ASSERT(mBufferPosition < aBufferMax);
|
MOZ_ASSERT(mBufferPosition < aBufferMax);
|
||||||
BorrowFromInputBuffer(aOutput, aChannels);
|
BorrowFromInputBuffer(aOutput, aChannels);
|
||||||
|
@ -534,11 +544,11 @@ public:
|
||||||
SpeexResamplerState* mResampler;
|
SpeexResamplerState* mResampler;
|
||||||
// mRemainingResamplerTail, like mBufferPosition, and
|
// mRemainingResamplerTail, like mBufferPosition, and
|
||||||
// mBufferEnd, is measured in input buffer samples.
|
// mBufferEnd, is measured in input buffer samples.
|
||||||
int mRemainingResamplerTail;
|
uint32_t mRemainingResamplerTail;
|
||||||
int32_t mBufferEnd;
|
uint32_t mBufferEnd;
|
||||||
int32_t mLoopStart;
|
uint32_t mLoopStart;
|
||||||
int32_t mLoopEnd;
|
uint32_t mLoopEnd;
|
||||||
int32_t mBufferPosition;
|
uint32_t mBufferPosition;
|
||||||
int32_t mBufferSampleRate;
|
int32_t mBufferSampleRate;
|
||||||
int32_t mResamplerOutRate;
|
int32_t mResamplerOutRate;
|
||||||
uint32_t mChannels;
|
uint32_t mChannels;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче