Skip to content

Commit 9d05c55

Browse files
committed
Crash when trying to suspend an OfflineAudioContext with a bad buffer
https://bugs.webkit.org/show_bug.cgi?id=219496 Reviewed by Geoffrey Garen. Source/WebCore: Test: webaudio/OfflineAudioContext-bad-buffer-suspend-crash.html * Modules/webaudio/OfflineAudioContext.cpp: (WebCore::OfflineAudioContext::startOfflineRendering): Throw a NotSupportedError for consistency with Blink. (WebCore::OfflineAudioContext::suspendOfflineRendering): Use length() instead of dereferencing the potentially null renderTarget to get the length. LayoutTests: Add layout test coverage. * webaudio/OfflineAudioContext-bad-buffer-suspend-crash-expected.txt: Added. * webaudio/OfflineAudioContext-bad-buffer-suspend-crash.html: Added. Canonical link: https://commits.webkit.org/232091@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@270408 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 6437c2e commit 9d05c55

6 files changed

Lines changed: 70 additions & 3 deletions

File tree

LayoutTests/ChangeLog

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
2020-12-03 Chris Dumez <cdumez@apple.com>
2+
3+
Crash when trying to suspend an OfflineAudioContext with a bad buffer
4+
https://bugs.webkit.org/show_bug.cgi?id=219496
5+
6+
Reviewed by Geoffrey Garen.
7+
8+
Add layout test coverage.
9+
10+
* webaudio/OfflineAudioContext-bad-buffer-suspend-crash-expected.txt: Added.
11+
* webaudio/OfflineAudioContext-bad-buffer-suspend-crash.html: Added.
12+
113
2020-12-03 Aditya Keerthi <akeerthi@apple.com>
214

315
[iOS][FCR] Add new look for search fields
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
CONSOLE MESSAGE: Failed to construct internal AudioBuffer with 1 channel(s), a sample rate of 8000 and a length of 4294967295.
2+
Tests that we do not crash when trying to suspend an OfflineAudioContext with a bad buffer.
3+
4+
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
5+
6+
7+
PASS context.sampleRate is 8000
8+
PASS context.length is 4294967295
9+
PASS context.state is "suspended"
10+
PASS startRendering() promise should get rejected. rejected promise with NotSupportedError: Failed to create audio buffer.
11+
PASS context.state is "suspended"
12+
PASS successfullyParsed is true
13+
14+
TEST COMPLETE
15+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<body>
4+
<script src="../resources/js-test.js"></script>
5+
<script>
6+
description("Tests that we do not crash when trying to suspend an OfflineAudioContext with a bad buffer.");
7+
jsTestIsAsync = true;
8+
9+
async function test() {
10+
context = new OfflineAudioContext({ length: -1, sampleRate: 8000 });
11+
context.suspend(0);
12+
shouldBe("context.sampleRate", "8000");
13+
shouldBe("context.length", "4294967295");
14+
shouldBeEqualToString("context.state", "suspended");
15+
await shouldRejectWithErrorName("context.startRendering()", "NotSupportedError", "startRendering() promise should get rejected.");
16+
shouldBeEqualToString("context.state", "suspended");
17+
finishJSTest();
18+
}
19+
20+
onload = test;
21+
</script>
22+
</body>
23+
</html>

LayoutTests/webaudio/dom-exceptions-expected.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ PASS new OfflineAudioContext(1, 0, 44100) threw SyntaxError: "length cannot be
152152
PASS < [invalid-offline-audio-context-parameters] All assertions passed. (total 5 assertions)
153153
PASS > [invalid-frame-length]
154154
PASS testContext = new OfflineAudioContext(1, -88200000000000, 44100) did not throw an exception.
155-
PASS testContext.startRendering() rejected correctly with InvalidStateError: Failed to create audio buffer.
155+
PASS testContext.startRendering() rejected correctly with NotSupportedError: Failed to create audio buffer.
156156
PASS < [invalid-frame-length] All assertions passed. (total 2 assertions)
157157
PASS > [waveshaper]
158158
PASS node.oversample = "9x" did not throw an exception.

Source/WebCore/ChangeLog

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
2020-12-03 Chris Dumez <cdumez@apple.com>
2+
3+
Crash when trying to suspend an OfflineAudioContext with a bad buffer
4+
https://bugs.webkit.org/show_bug.cgi?id=219496
5+
6+
Reviewed by Geoffrey Garen.
7+
8+
Test: webaudio/OfflineAudioContext-bad-buffer-suspend-crash.html
9+
10+
* Modules/webaudio/OfflineAudioContext.cpp:
11+
(WebCore::OfflineAudioContext::startOfflineRendering):
12+
Throw a NotSupportedError for consistency with Blink.
13+
14+
(WebCore::OfflineAudioContext::suspendOfflineRendering):
15+
Use length() instead of dereferencing the potentially null renderTarget to get
16+
the length.
17+
118
2020-12-03 Chris Dumez <cdumez@apple.com>
219

320
Refactor macros for low power mode code

Source/WebCore/Modules/webaudio/OfflineAudioContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void OfflineAudioContext::startOfflineRendering(Ref<DeferredPromise>&& promise)
103103
}
104104

105105
if (!renderTarget()) {
106-
promise->reject(Exception { InvalidStateError, "Failed to create audio buffer"_s });
106+
promise->reject(Exception { NotSupportedError, "Failed to create audio buffer"_s });
107107
return;
108108
}
109109

@@ -134,7 +134,7 @@ void OfflineAudioContext::suspendOfflineRendering(double suspendTime, Ref<Deferr
134134
return;
135135
}
136136

137-
double totalRenderDuration = renderTarget()->length() / sampleRate();
137+
double totalRenderDuration = length() / sampleRate();
138138
if (totalRenderDuration <= suspendTime) {
139139
promise->reject(Exception { InvalidStateError, "suspendTime cannot be greater than total rendering duration"_s });
140140
return;

0 commit comments

Comments
 (0)