Skip to content

Commit 3fe28c6

Browse files
nipunshukla21jyavenard
authored andcommitted
REGRESSION (Safari 26): AudioData.copyTo() crashes the tab with valid conversion
https://bugs.webkit.org/show_bug.cgi?id=302521 rdar://164730320 Reviewed by Jean-Yves Avenard. The RELEASE_ASSERT in PlatformRawAudioDataCocoa::copyTo() required (increment - 2) more elements than necessary. This caused crashes when copying planeIndex 2 from 3-channel AudioData. Test: http/wpt/webcodecs/audioData-copyTo-last-channel-does-not-crash.html * LayoutTests/http/wpt/webcodecs/audioData-copyTo-last-channel-does-not-crash-expected.txt: Added. * LayoutTests/http/wpt/webcodecs/audioData-copyTo-last-channel-does-not-crash.html: Added. * Source/WebCore/platform/audio/cocoa/PlatformRawAudioDataCocoa.cpp: (WebCore::PlatformRawAudioData::copyTo): Canonical link: https://commits.webkit.org/304728@main
1 parent 5ab99ca commit 3fe28c6

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
PASS Test that copying last channel from interleaved to planar does not crash
3+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<header>
4+
<script src='/resources/testharness.js'></script>
5+
<script src='/resources/testharnessreport.js'></script>
6+
</header>
7+
<body>
8+
<script>
9+
test(() => {
10+
const data = new AudioData({
11+
numberOfChannels: 3,
12+
data: new Float32Array([1, 1, 1]),
13+
format: 'f32',
14+
numberOfFrames: 1,
15+
sampleRate: 48000,
16+
timestamp: 0,
17+
});
18+
19+
const dataBytes = new Float32Array(1);
20+
data.copyTo(dataBytes, {planeIndex: 2, format: 'f32-planar'});
21+
22+
data.close();
23+
}, 'Test that copying last channel from interleaved to planar does not crash');
24+
</script>
25+
</body>
26+
</html>

Source/WebCore/platform/audio/cocoa/PlatformRawAudioDataCocoa.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ void PlatformRawAudioData::copyTo(std::span<uint8_t> destination, AudioSampleFor
287287

288288
auto copyElements = []<typename T>(std::span<T> destination, auto sourcePlane, size_t sampleOffset, size_t sampleIndexIncrement, size_t samples) {
289289
RELEASE_ASSERT(destination.size() >= samples);
290-
RELEASE_ASSERT(sourcePlane.size() >= sampleIndexIncrement * samples + sampleOffset - 1);
290+
RELEASE_ASSERT(sourcePlane.size() > sampleOffset + (samples - 1) * sampleIndexIncrement);
291291
size_t sourceSampleIndex = sampleOffset;
292292
for (size_t sample = 0; sample < samples; sample++) {
293293
destination[sample] = convertAudioSample<T>(sourcePlane[sourceSampleIndex]);

0 commit comments

Comments
 (0)