Bug 875144 - Disallow creating AudioBuffers of 0 length; r=roc

This commit is contained in:
Ehsan Akhgari 2013-05-23 22:39:36 -04:00
parent 03aface63f
commit 3e5b5e657d
6 changed files with 102 additions and 6 deletions

View File

@ -0,0 +1,81 @@
<script>
Logger = {}
Logger.error = function(e) {}
Logger.comment = function(e) {}
try { o0 = document.createElement('audio'); } catch(e) { Logger.error(Logger.comment(e)); }
try { (document.body || document.documentElement).appendChild(o0); } catch(e) { Logger.error(Logger.comment(e)); }
try { o1 = new AudioContext(); } catch(e) { Logger.error(Logger.comment(e)); }
try { o2 = o1.createGain(); } catch(e) { Logger.error(Logger.comment(e)); }
try { o3 = o1.createBufferSource(); } catch(e) { Logger.error(Logger.comment(e)); }
try { o3.buffer = function() { o4 = o1.createBuffer(1, 3, 52970);
o5 = o4.getChannelData(0);
for(var i=0; i<3; ++i) {
o5[i] = Math.sin(i * 63);
}
return o4;
}(); } catch(e) { Logger.error(Logger.comment(e)); }
try { o3.buffer = function() { o6 = o1.createBuffer(1, 15, 41218);
o7 = o6.getChannelData(0);
for(var i=0; i<15; ++i) {
o7[i] = Math.sin(i * 0);
}
return o6;
}(); } catch(e) { Logger.error(Logger.comment(e)); }
try { o3.buffer = function() { o8 = o1.createBuffer(1, 0, 49074);
o9 = o8.getChannelData(0);
for(var i=0; i<0; ++i) {
o9[i] = Math.sin(i * 0);
}
return o8;
}(); } catch(e) { Logger.error(Logger.comment(e)); }
try { o3.buffer = function() { o10 = o1.createBuffer(1, 31, 86527);
o11 = o10.getChannelData(0);
for(var i=0; i<31; ++i) {
o11[i] = Math.sin(i * 127);
}
return o10;
}(); } catch(e) { Logger.error(Logger.comment(e)); }
try { o3.noteOff(-1) } catch(e) { Logger.error(Logger.comment(e)); }
/* [Exception... "An attempt was made to use an object that is not, or is no longer, usable" code: "11" nsresult: "0x8053000b (InvalidStateError)" location: "file:///Users/cdiehl/dev/projects/peach/Peach/Utilities/JS/undefined.js Line: 602"] */
try { o3.channelCountMode = 'explicit'; } catch(e) { Logger.error(Logger.comment(e)); }
try { o12 = o1.createBiquadFilter(); } catch(e) { Logger.error(Logger.comment(e)); }
try { o3.buffer = function() { o13 = o1.createBuffer(1, 63, 28347);
o14 = o13.getChannelData(0);
for(var i=0; i<63; ++i) {
o14[i] = Math.sin(i * 15);
}
return o13;
}(); } catch(e) { Logger.error(Logger.comment(e)); }
try { o12.channelCount = 1; } catch(e) { Logger.error(Logger.comment(e)); }
try { o12.connect(GainNode, 65536, 0) } catch(e) { Logger.error(Logger.comment(e)); }
/* TypeError: Value does not implement interface AudioNode. */
try { o3.buffer = function() { o15 = o1.createBuffer(1, 1, 72540);
o16 = o15.getChannelData(0);
for(var i=0; i<1; ++i) {
o16[i] = Math.sin(i * 7);
}
return o15;
}(); } catch(e) { Logger.error(Logger.comment(e)); }
try { o12.getFrequencyResponse(Float32Array(7), Float32Array(127), Float32Array(7)) } catch(e) { Logger.error(Logger.comment(e)); }
try { o12.getFrequencyResponse(Float32Array(15), Float32Array(127), Float32Array(7)) } catch(e) { Logger.error(Logger.comment(e)); }
try { o17 = document.createElement('audio'); } catch(e) { Logger.error(Logger.comment(e)); }
try { (document.body || document.documentElement).appendChild(o0); } catch(e) { Logger.error(Logger.comment(e)); }
try { o3.buffer = function() { o18 = o1.createBuffer(1, 7, 91261);
o19 = o18.getChannelData(0);
for(var i=0; i<7; ++i) {
o19[i] = Math.sin(i * 7);
}
return o18;
}(); } catch(e) { Logger.error(Logger.comment(e)); }
try { o12.getFrequencyResponse(Float32Array(31), Float32Array(31), Float32Array(127)) } catch(e) { Logger.error(Logger.comment(e)); }
try { o20 = o1.createChannelSplitter(1, 2, 4, 16, 32); } catch(e) { Logger.error(Logger.comment(e)); }
try { o12.channelCountMode = 'explicit'; } catch(e) { Logger.error(Logger.comment(e)); }
try { o3.buffer = function() { o21 = o1.createBuffer(1, 0, 14451);
o22 = o21.getChannelData(0);
for(var i=0; i<0; ++i) {
o22[i] = Math.sin(i * 63);
}
return o21;
}(); } catch(e) { Logger.error(Logger.comment(e)); }
</script>

View File

@ -19,3 +19,4 @@ load 874869.html
load 874915.html
load 874934.html
load 874952.html
load 875144.html

View File

@ -136,8 +136,8 @@ AudioContext::CreateBuffer(JSContext* aJSContext, uint32_t aNumberOfChannels,
uint32_t aLength, float aSampleRate,
ErrorResult& aRv)
{
if (aSampleRate < 8000 || aSampleRate > 96000) {
aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
if (aSampleRate < 8000 || aSampleRate > 96000 || !aLength) {
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
return nullptr;
}

View File

@ -37,12 +37,15 @@ addLoadEvent(function() {
}
expectException(function() {
context.createBuffer(2, 2048, 7999);
}, DOMException.SYNTAX_ERR);
}, DOMException.NOT_SUPPORTED_ERR);
expectException(function() {
context.createBuffer(2, 2048, 96001);
}, DOMException.SYNTAX_ERR);
}, DOMException.NOT_SUPPORTED_ERR);
context.createBuffer(2, 2048, 8000); // no exception
context.createBuffer(2, 2048, 96000); // no exception
expectException(function() {
context.createBuffer(2, 0, 48000);
}, DOMException.NOT_SUPPORTED_ERR);
SpecialPowers.clearUserPref("media.webaudio.enabled");
SimpleTest.finish();
});

View File

@ -14,15 +14,26 @@ var gTest = {
length: 2048,
numberOfChannels: 1,
createGraph: function(context) {
var buffer = context.createBuffer(1, 0, context.sampleRate);
var buffer = context.createBuffer(1, 2048, context.sampleRate);
for (var i = 0; i < 2048; ++i) {
buffer.getChannelData(0)[i] = Math.sin(440 * 2 * Math.PI * i / context.sampleRate);
}
var source = context.createBufferSource();
source.buffer = buffer;
source.loop = true;
source.loopStart = source.loopEnd = 1 / context.sampleRate;
source.start(0);
return source;
},
createExpectedBuffers: function(context) {
var buffer = context.createBuffer(1, 2048, context.sampleRate);
for (var i = 0; i < 2048; ++i) {
buffer.getChannelData(0)[i] = Math.sin(440 * 2 * Math.PI * i / context.sampleRate);
}
return buffer;
},
};
runTest();

View File

@ -11,7 +11,7 @@
SpecialPowers.setBoolPref("media.webaudio.enabled", true);
var ctx = new AudioContext();
ctx.createBuffer(0, 0, ctx.sampleRate);
ctx.createBuffer(0, 1, ctx.sampleRate);
ok(true, "The test should not crash during CC");
SpecialPowers.clearUserPref("media.webaudio.enabled");