From addadf92a10d940530ae21a14817e1da3822c11f Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Tue, 14 Sep 2021 03:38:52 +0200 Subject: [PATCH] [HTML5] Fix bug in AudioWorklet when reading output buffer. Would attempt an out of bounds read, causing an exception. (cherry picked from commit ba08f39e47f12c6910388f41367305c93eaa06e4) --- platform/javascript/js/libs/audio.worklet.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/platform/javascript/js/libs/audio.worklet.js b/platform/javascript/js/libs/audio.worklet.js index 6b3f80c6a94..d109e4033df 100644 --- a/platform/javascript/js/libs/audio.worklet.js +++ b/platform/javascript/js/libs/audio.worklet.js @@ -66,17 +66,17 @@ class RingBuffer { const mw = this.buffer.length - this.wpos; if (mw >= to_write) { this.buffer.set(p_buffer, this.wpos); + this.wpos += to_write; + if (mw === to_write) { + this.wpos = 0; + } } else { - const high = p_buffer.subarray(0, to_write - mw); - const low = p_buffer.subarray(to_write - mw); + const high = p_buffer.subarray(0, mw); + const low = p_buffer.subarray(mw); this.buffer.set(high, this.wpos); this.buffer.set(low); + this.wpos = low.length; } - let diff = to_write; - if (this.wpos + diff >= this.buffer.length) { - diff -= this.buffer.length; - } - this.wpos += diff; Atomics.add(this.avail, 0, to_write); Atomics.notify(this.avail, 0); }