Out of bounds read in FFmpeg (CVE-2026-13858)
A crafted HEVC MP4 makes FFmpeg's mov_seek_stream retry path pass a negative sample index into can_seek_to_key_sample, whose bounds check only rejects values that are too large. Seeking in a video element then causes an 8-byte heap out-of-bounds read in the sandboxed renderer.
- Fix shipped in 2 months
Report description
Heap-buffer-overflow read in libavformat mov_seek_stream / can_seek_to_key_sample via a crafted HEVC MP4 and an HTMLMediaElement seek
Bug location
Where do you want to report your vulnerability?
Chrome VRP – Report security issues affecting the Chrome browser. See program rules
Which URL (or repository) have you found the vulnerability in?
https://chromium.googlesource.com/chromium/src
The problem
Please describe the technical details of the vulnerability
Summary
A crafted MP4 with one HEVC video track and one valid Opus audio track makes libavformat's mov_seek_stream retry path call can_seek_to_key_sample(st, requested_sample, next_ts) with requested_sample = -1. The bounds guard at third_party/ffmpeg/libavformat/mov.c:11601 is a signed int compare (if (sample >= sc->sample_offsets_count)) and lets -1 through, after which line 11604 reads sti->index_entries[-1].timestamp — an 8-byte heap out-of-bounds READ 16 bytes before a 1536-byte index_entries buffer allocated by av_reallocp_array. Trigger is <video src=poc.mp4> plus a JS video.currentTime = 0 (or any value mapping to PTS 0 on the HEVC track); no user gesture, autoplay opt-in, or experimental feature flag is required for the web trigger.
Affected versions
- Crash reproduced and ASAN log captured on 149.0.7802.0 Linux ASAN. The Chromium
149.0.7802.0tag pinsthird_party/ffmpegto thechromium/third_party/ffmpegfork atb5e18fb9da84e26ceef30d4e4886696bf59337c0. - Source reviewed in a Chromium checkout from 2026-04-27 whose DEPS pin
third_party/ffmpegto64c21ea132c48271dd3ce497eeb008187eb7d3f1; the vulnerable hunk is still present there.third_party/ffmpegfile:lineanchors below refer to that pinned ffmpeg revision. Chromium-sideffmpeg_demuxer.ccreferences are by function name because line numbers may drift between Chromium checkouts. Both pins contain the prerequisite commit identified in the Bisect section.
Root cause
Three conditions compose:
-
can_seek_to_key_sampleuses a signed-intupper-bound compare.third_party/ffmpeg/libavformat/mov.c:11592-11616:C static int can_seek_to_key_sample(AVStream *st, int sample, int64_t requested_pts) { MOVStreamContext *sc = st->priv_data; FFStream *const sti = ffstream(st); int64_t key_sample_dts, key_sample_pts; if (st->codecpar->codec_id != AV_CODEC_ID_HEVC) return 1; if (sample >= sc->sample_offsets_count) // sample is int, count is int — sample = -1 passes return 1; key_sample_dts = sti->index_entries[sample].timestamp; // line 11604: OOB read key_sample_pts = key_sample_dts + sc->sample_offsets[sample] + sc->dts_shift; if (is_open_key_sample(sc, sample) && key_sample_pts > requested_pts) return 0; return 1; }MOVStreamContext::sample_offsets_countisint(signed) atthird_party/ffmpeg/libavformat/isom.h:247, so the only guard rejectssample >= countbut neversample < 0. -
The retry path in
mov_seek_streamfeeds the result ofav_index_search_timestamp(..., flags)straight intocan_seek_to_key_sample.third_party/ffmpeg/libavformat/mov.c:11634-11655:C for (;;) { sample = av_index_search_timestamp(st, timestamp, flags); if (sample < 0 && sti->nb_index_entries && timestamp < sti->index_entries[0].timestamp) sample = 0; // fix-up applies only to the first call if (sample < 0) return AVERROR_INVALIDDATA; if (!sample || can_seek_to_key_sample(st, sample, timestamp)) break; next_ts = timestamp - FFMAX(sc->min_sample_duration, 1); // crafted file: min_sample_duration = 0, so next_ts = timestamp - 1 requested_sample = av_index_search_timestamp(st, next_ts, flags);// returns -1 when no entry has ts <= next_ts if (sample != requested_sample && !can_seek_to_key_sample(st, requested_sample, next_ts)) break; // requested_sample = -1 reaches the function with no fix-up timestamp = next_ts; }The fix-up after the first
av_index_search_timestampis not mirrored onrequested_sample, so-1flows directly into condition (1). -
The crafted MP4 forces the first
can_seek_to_key_samplecall to return 0, so the retry path is taken. The firstav_index_search_timestampreturns a non-zero midpoint sample. For that sample,can_seek_to_key_sampleevaluatesis_open_key_sample(midpoint) && key_sample_pts > requested_pts; the crafted MP4 makes both true, so the function returns 0 and the loop falls into the retry path.make_poc_mp4.pybuilds a moov withsttscount=4 duration=0(somin_sample_duration = 0),cttsoffsets[100,200,300,400,...](sokey_sample_pts > 0for any midpoint),stssmarking every sample sync, ansgpdofgrouping_type=syncwhose first entry hasnal_unit_type = HEVC_NAL_CRA_NUT (21), and N separatesbgpentries each withcount=1, group_description_index=1. The split-sbgpshape is required becausebuild_open_gop_key_pointsatthird_party/ffmpeg/libavformat/mov.c:4631-4640uses a constantsample_idinside the inner loop and only ratchetssample_idbetween outersbgpentries:C for (uint32_t i = 0; i < sc->sync_group_count; i++) { const MOVSbgp *sg = &sc->sync_group[i]; if (sg->index == cra_index) for (uint32_t j = 0; j < sg->count; j++) sc->open_key_samples[k++] = sample_id; // inner loop sees a fixed sample_id sample_id += sg->count; // ratchets only between outer entries }With one
sbgpentry ofcount=N,open_key_samplesbecomes[0,0,...,0]andis_open_key_sample(midpoint) = 0, so the firstcan_seek_to_key_samplereturns 1 and the retry path is never entered. With N per-samplesbgpentries ofcount=1,open_key_samples = [0,1,...,N-1],is_open_key_sample(midpoint) = 1, the first call returns 0, and the loop falls into the OOB second call.
The HEVC track does not have to be supported by the Chromium media stack. On Chromium-branded builds with ENABLE_PLATFORM_HEVC=false, FFmpegDemuxerStream::Create rejects the HEVC AVStream, but FFmpegDemuxer::OnFindStreamInfoDone only logs the unsupported video track and continues from the stream-construction loop. It does not set stream->discard = AVDISCARD_ALL for that HEVC AVStream. The HEVC stream therefore remains in format_context->streams[]. When a seek is then issued for the surviving Opus track, mov_read_seek walks every stream because seek_individually defaults to 1 (third_party/ffmpeg/libavformat/mov.c:11725-11742, default at :11773), so mov_seek_stream runs on the zombie HEVC stream and reaches the bug.
Reproduction
Extract the attached poc.html, poc.mp4, make_poc_mp4.py, and asan.log into an empty working directory and cd into it. Download the ASAN build into the same directory so that chrome and llvm-symbolizer sit next to the PoC files. All commands below are run from that directory; every path is relative.
-
Download the 149.0.7802.0 Linux ASAN build using
get_asan_chrome.py(which ships in the Chromium source tree attools/get_asan_chrome/get_asan_chrome.py):python3 get_asan_chrome.py --version 149.0.7802.0 --output-dir .Unzip the resulting archive and move
chrome,llvm-symbolizer, and the sibling runtime files into the working directory. -
Serve the PoC over a local HTTP origin (single command line):
python3 -m http.server 8000 -
In another shell, run the ASAN build against the PoC (single command line):
ASAN_OPTIONS=detect_leaks=0:symbolize=1:allocator_may_return_null=1:halt_on_error=1:external_symbolizer_path=./llvm-symbolizer ./chrome --no-sandbox --user-data-dir=/tmp/asan_profile --headless=new --no-first-run --disable-breakpad --disable-crash-reporter "http://127.0.0.1:8000/poc.html" 2> asan.log
make_poc_mp4.py is the deterministic builder for poc.mp4; running it regenerates the same 26 KB MP4 used to capture the attached asan.log. The attached asan.log was captured with the command above.
Crash evidence
From asan.log:
==343409==ERROR: AddressSanitizer: use-after-poison on address 0x7449f7300d70 at pc 0x59cbcbeeadcc bp 0x7299ee5992a0 sp 0x7299ee599298
READ of size 8 at 0x7449f7300d70 thread T4 (ThreadPoolForeg)
#0 0x59cbcbeeadcb in mov_seek_stream third_party/ffmpeg/libavformat/mov.c:11604:49
Allocation context (the buffer the read is past):
0x7449f7300d70 is located 16 bytes before 1536-byte region [0x7449f7300d80,0x7449f7301380)
allocated by thread T4 (ThreadPoolForeg) here:
#0 realloc
#1 av_reallocp_array third_party/ffmpeg/libavutil/mem.c:165:11
ASAN labels the report use-after-poison because the byte before the user region is poisoned by PartitionAlloc (Chromium's heap allocator) via __asan_poison_memory_region rather than ASAN's own malloc-shim left-redzone. The semantic is identical to heap-buffer-overflow — a read past the start of an allocation. The crashing process is the renderer, confirmed by the command line in the log's ADDITIONAL INFO block (/proc/self/exe --type=renderer ...). The task trace shows the crash on the media demuxer seek path: media::FFmpegDemuxer::SeekInternal posts AVSeekFrame to a blocking task runner, and the OOB read fires on that runner's ThreadPoolForeg thread.
Bisect
The bug landed when the retry path in mov_seek_stream was added; before that commit, the loop just decremented timestamp without making a second can_seek_to_key_sample call, so no caller ever passed a negative sample.
- Commit:
d1b96c380826c505a8c7e655b5ad4fdb0c2de167(FFmpeg upstream; carried into Chromium'schromium/third_party/ffmpegfork) - Subject:
avformat/mov: avoid seeking back to 0 on HEVC open GOP files - Date: 2024-05-21
- Upstream URL: https://git.ffmpeg.org/gitweb/ffmpeg.git/commit/d1b96c380826c505a8c7e655b5ad4fdb0c2de167
The exact hunk that introduces the unguarded second call:
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -10133,7 +10133,7 @@ static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp,
{
MOVStreamContext *sc = st->priv_data;
FFStream *const sti = ffstream(st);
- int sample, time_sample, ret;
+ int sample, time_sample, ret, next_ts, requested_sample;
unsigned int i;
@@ -10154,7 +10154,17 @@ static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp,
if (!sample || can_seek_to_key_sample(st, sample, timestamp))
break;
- timestamp -= FFMAX(sc->min_sample_duration, 1);
+ next_ts = timestamp - FFMAX(sc->min_sample_duration, 1);
+ requested_sample = av_index_search_timestamp(st, next_ts, flags);
+ if (!can_seek_to_key_sample(st, requested_sample, next_ts) && sample != requested_sample)
+ break;
+ timestamp = next_ts;
}
The earlier prerequisite that introduced can_seek_to_key_sample itself is FFmpeg ab77b878f1 (https://git.ffmpeg.org/gitweb/ffmpeg.git/commit/ab77b878f1, "avformat/mov: fix seeking with HEVC open GOP files", 2022-05-19). The first chromium fork merge that pulled d1b96c3808 into chromium/third_party/ffmpeg is d4258358c7672ae3ccaac0ffb16c5169bbff273c (https://chromium.googlesource.com/chromium/third_party/ffmpeg/+/d4258358c7672ae3ccaac0ffb16c5169bbff273c, 2024-09-20). Both the 149.0.7802.0 pin (b5e18fb9da...) and the current pin (64c21ea132...) include all of these prerequisites.
Suggested patch
Tighten can_seek_to_key_sample's bounds check to reject negative sample in addition to over-large values:
--- a/third_party/ffmpeg/libavformat/mov.c
+++ b/third_party/ffmpeg/libavformat/mov.c
@@ -11598,7 +11598,8 @@ static int can_seek_to_key_sample(AVStream *st, int sample, int64_t requested_pt
if (st->codecpar->codec_id != AV_CODEC_ID_HEVC)
return 1;
- if (sample >= sc->sample_offsets_count)
+ if (sample < 0 || sample >= sti->nb_index_entries ||
+ sample >= sc->sample_offsets_count)
return 1;
key_sample_dts = sti->index_entries[sample].timestamp;
Rationale: sample is int, and the function reads sti->index_entries[sample] and sc->sample_offsets[sample] immediately after. av_index_search_timestamp is documented to return a negative number when no matching entry exists; the existing fix-up at mov_seek_stream:11637 only catches the first call's negative result. Rejecting sample < 0 and bounding against both nb_index_entries and sample_offsets_count at the function boundary closes the OOB read where it happens and matches the two array accesses on the next two lines.
Impact analysis
ASAN reports an out-of-bounds heap READ of size 8, landing 16 bytes before the start of a 1536-byte index_entries allocation, inside the renderer process (sandboxed). The trigger is a <video src=...> element pointing at the crafted MP4 plus a single video.currentTime seek.
The cause
What version of Chrome have you found the security issue in?
149.0.7802.0 dev
Is the security issue related to a crash?
Yes, it is related to a crash.
Choose the type of vulnerability
Memory Corruption (in a sandboxed process)
How would you like to be publicly acknowledged for your report?
Wongi Lee (@_qwerty_po) of Theori with Xint Code, Jungwoo Lee (@physicube).
Context
This is a Chrome VRP report about a heap out-of-bounds read inside the FFmpeg copy that Chromium ships in third_party/ffmpeg. The vulnerable code is in libavformat's MP4 demuxer, specifically the seek path used when a media element asks to move to a new playback position.
Normally, when a page sets video.currentTime, Chromium's media pipeline asks the demuxer to seek. For MP4 files, mov_seek_stream maps the requested timestamp to a sample index with av_index_search_timestamp, then, for HEVC streams, checks with can_seek_to_key_sample whether that sample is an open key sample that would land after the requested point. If it is, the loop steps back one timestamp and tries again. The report shows that this retry path can pass a negative sample index into can_seek_to_key_sample, which then indexes an array with -1.
The bug was reported through the Chrome Vulnerability Reward Program against the Chromium source repository at https://chromium.googlesource.com/chromium/src, and was assessed as medium severity with a 3000 USD reward. It was disclosed on 2026-06-30.
Setup
The crash was reproduced on the Linux ASAN build of Chrome 149.0.7802.0. That tag pins third_party/ffmpeg to the chromium/third_party/ffmpeg fork at commit [redacted].
The source was also reviewed in a Chromium checkout from 2026-04-27 whose DEPS pin third_party/ffmpeg to [redacted]; the vulnerable hunk is present there too. The file:line anchors in the report refer to that pinned FFmpeg revision. Chromium-side ffmpeg_demuxer.cc references are given by function name because line numbers drift between checkouts. Both pins contain the prerequisite commit described under Bisect.
The reproduction needs four attached files, poc.html, poc.mp4, make_poc_mp4.py and asan.log, plus the ASAN build itself. No account, gesture, autoplay opt-in or experimental feature flag is needed for the web trigger.
Finding it
The researcher identified three conditions that compose into the bug.
-
can_seek_to_key_sampleuses a signedintupper-bound compare. The function atthird_party/ffmpeg/libavformat/mov.c:11592-11616is:C static int can_seek_to_key_sample(AVStream *st, int sample, int64_t requested_pts) { MOVStreamContext *sc = st->priv_data; FFStream *const sti = ffstream(st); int64_t key_sample_dts, key_sample_pts; if (st->codecpar->codec_id != AV_CODEC_ID_HEVC) return 1; if (sample >= sc->sample_offsets_count) // sample is int, count is int — sample = -1 passes return 1; key_sample_dts = sti->index_entries[sample].timestamp; // line 11604: OOB read key_sample_pts = key_sample_dts + sc->sample_offsets[sample] + sc->dts_shift; if (is_open_key_sample(sc, sample) && key_sample_pts > requested_pts) return 0; return 1; }MOVStreamContext::sample_offsets_countis a signedintatthird_party/ffmpeg/libavformat/isom.h:247, so the only guard rejectssample >= countand neversample < 0. -
The retry path in
mov_seek_streamfeeds the result ofav_index_search_timestampstraight intocan_seek_to_key_sample. The loop atthird_party/ffmpeg/libavformat/mov.c:11634-11655is:C for (;;) { sample = av_index_search_timestamp(st, timestamp, flags); if (sample < 0 && sti->nb_index_entries && timestamp < sti->index_entries[0].timestamp) sample = 0; // fix-up applies only to the first call if (sample < 0) return AVERROR_INVALIDDATA; if (!sample || can_seek_to_key_sample(st, sample, timestamp)) break; next_ts = timestamp - FFMAX(sc->min_sample_duration, 1); // crafted file: min_sample_duration = 0, so next_ts = timestamp - 1 requested_sample = av_index_search_timestamp(st, next_ts, flags);// returns -1 when no entry has ts <= next_ts if (sample != requested_sample && !can_seek_to_key_sample(st, requested_sample, next_ts)) break; // requested_sample = -1 reaches the function with no fix-up timestamp = next_ts; }The fix-up applied after the first
av_index_search_timestampis not mirrored onrequested_sample, so-1flows directly into condition 1. -
The crafted MP4 forces the first
can_seek_to_key_samplecall to return 0, so the retry path is taken. The firstav_index_search_timestampreturns a non-zero midpoint sample. For that sample,can_seek_to_key_sampleevaluatesis_open_key_sample(midpoint) && key_sample_pts > requested_pts; the crafted file makes both true, so the function returns 0 and the loop enters the retry path.
make_poc_mp4.py builds a moov with stts count=4 duration=0 (so min_sample_duration = 0), ctts offsets [100,200,300,400,...] (so key_sample_pts > 0 for any midpoint), stss marking every sample sync, an sgpd of grouping_type=sync whose first entry has nal_unit_type = HEVC_NAL_CRA_NUT (21), and N separate sbgp entries each with count=1, group_description_index=1.
The split-sbgp shape is required because build_open_gop_key_points at third_party/ffmpeg/libavformat/mov.c:4631-4640 uses a constant sample_id inside the inner loop and only ratchets sample_id between outer sbgp entries:
for (uint32_t i = 0; i < sc->sync_group_count; i++) {
const MOVSbgp *sg = &sc->sync_group[i];
if (sg->index == cra_index)
for (uint32_t j = 0; j < sg->count; j++)
sc->open_key_samples[k++] = sample_id; // inner loop sees a fixed sample_id
sample_id += sg->count; // ratchets only between outer entries
}
With one sbgp entry of count=N, open_key_samples becomes [0,0,...,0] and is_open_key_sample(midpoint) = 0, so the first can_seek_to_key_sample returns 1 and the retry path is never entered. With N per-sample sbgp entries of count=1, open_key_samples = [0,1,...,N-1], is_open_key_sample(midpoint) = 1, the first call returns 0, and the loop falls into the out-of-bounds second call.
The HEVC track does not have to be supported by the Chromium media stack. On Chromium-branded builds with ENABLE_PLATFORM_HEVC=false, FFmpegDemuxerStream::Create rejects the HEVC AVStream, but FFmpegDemuxer::OnFindStreamInfoDone only logs the unsupported video track and continues from the stream-construction loop. It does not set stream->discard = AVDISCARD_ALL for that HEVC AVStream. The HEVC stream therefore remains in format_context->streams[]. When a seek is then issued for the surviving Opus track, mov_read_seek walks every stream because seek_individually defaults to 1 (third_party/ffmpeg/libavformat/mov.c:11725-11742, default at :11773), so mov_seek_stream runs on the zombie HEVC stream and reaches the bug.
Exploitation
Step 1: prepare the working directory
Extract poc.html, poc.mp4, make_poc_mp4.py and asan.log into an empty directory and cd into it. Download the ASAN build into the same directory so that chrome and llvm-symbolizer sit next to the PoC files. All commands below are run from that directory and every path is relative.
Step 2: fetch the ASAN build
Use get_asan_chrome.py, which ships in the Chromium source tree at tools/get_asan_chrome/get_asan_chrome.py:
python3 get_asan_chrome.py --version 149.0.7802.0 --output-dir .
Unzip the resulting archive and move chrome, llvm-symbolizer and the sibling runtime files into the working directory.
Step 3: serve the PoC
Start a local HTTP origin from the working directory:
python3 -m http.server 8000
Step 4: run the ASAN build against the PoC
In another shell, launch the browser headless against poc.html:
ASAN_OPTIONS=detect_leaks=0:symbolize=1:allocator_may_return_null=1:halt_on_error=1:external_symbolizer_path=./llvm-symbolizer ./chrome --no-sandbox --user-data-dir=/tmp/asan_profile --headless=new --no-first-run --disable-breakpad --disable-crash-reporter "http://[redacted]:8000/poc.html" 2> asan.log
The ASAN_OPTIONS disable leak detection, enable symbolisation through the local llvm-symbolizer, allow the allocator to return null, halt on the first error and point at the external symboliser. The Chrome flags run without the sandbox, use a throwaway profile, run headless, skip first-run and breakpad, and load the PoC page. Standard error is captured to asan.log.
make_poc_mp4.py is the deterministic builder for poc.mp4; running it regenerates the same 26 KB MP4 used to capture the attached asan.log. The attached log was captured with the command above.
Step 5: the web trigger
The page is <video src=poc.mp4> plus a JS video.currentTime = 0 (or any value mapping to PTS 0 on the HEVC track). No user gesture, autoplay opt-in or experimental feature flag is required.
Crash evidence
From asan.log:
==343409==ERROR: AddressSanitizer: use-after-poison on address 0x7449f7300d70 at pc 0x59cbcbeeadcc bp 0x7299ee5992a0 sp 0x7299ee599298
READ of size 8 at 0x7449f7300d70 thread T4 (ThreadPoolForeg)
#0 0x59cbcbeeadcb in mov_seek_stream third_party/ffmpeg/libavformat/mov.c:11604:49
Allocation context, the buffer the read is past:
0x7449f7300d70 is located 16 bytes before 1536-byte region [0x7449f7300d80,0x7449f7301380)
allocated by thread T4 (ThreadPoolForeg) here:
#0 realloc
#1 av_reallocp_array third_party/ffmpeg/libavutil/mem.c:165:11
ASAN labels the report use-after-poison because the byte before the user region is poisoned by PartitionAlloc (Chromium's heap allocator) via __asan_poison_memory_region rather than ASAN's own malloc-shim left-redzone. The semantic is identical to heap-buffer-overflow: a read past the start of an allocation. The crashing process is the renderer, confirmed by the command line in the log's ADDITIONAL INFO block (/proc/self/exe --type=renderer ...). The task trace shows the crash on the media demuxer seek path: media::FFmpegDemuxer::SeekInternal posts AVSeekFrame to a blocking task runner, and the out-of-bounds read fires on that runner's ThreadPoolForeg thread.
Root cause
The mistake is a missing lower bound. can_seek_to_key_sample takes sample as a signed int and immediately uses it to index sti->index_entries[sample] and sc->sample_offsets[sample], but its only guard is if (sample >= sc->sample_offsets_count). A value of -1 passes that check and the read at line 11604 lands 16 bytes before a 1536-byte index_entries buffer allocated by av_reallocp_array.
The negative value is produced legitimately: av_index_search_timestamp is documented to return a negative number when no matching entry exists. mov_seek_stream handles that for the first call with a fix-up that clamps to 0 when the timestamp precedes the first index entry, and returns AVERROR_INVALIDDATA for other negative results. The retry path added later calls av_index_search_timestamp a second time for next_ts and passes the result to can_seek_to_key_sample without any equivalent fix-up. With min_sample_duration = 0 in the crafted file, next_ts = timestamp - 1, and when no entry has a timestamp at or below next_ts, requested_sample is -1.
Bisect
The bug landed when the retry path in mov_seek_stream was added. Before that commit the loop just decremented timestamp without making a second can_seek_to_key_sample call, so no caller ever passed a negative sample.
- Commit:
[redacted](FFmpeg upstream; carried into Chromium'schromium/third_party/ffmpegfork) - Subject:
avformat/mov: avoid seeking back to 0 on HEVC open GOP files - Date: 2024-05-21
- Upstream URL: https://git.ffmpeg.org/gitweb/ffmpeg.git/commit/[redacted]
The exact hunk that introduces the unguarded second call:
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -10133,7 +10133,7 @@ static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp,
{
MOVStreamContext *sc = st->priv_data;
FFStream *const sti = ffstream(st);
- int sample, time_sample, ret;
+ int sample, time_sample, ret, next_ts, requested_sample;
unsigned int i;
@@ -10154,7 +10154,17 @@ static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp,
if (!sample || can_seek_to_key_sample(st, sample, timestamp))
break;
- timestamp -= FFMAX(sc->min_sample_duration, 1);
+ next_ts = timestamp - FFMAX(sc->min_sample_duration, 1);
+ requested_sample = av_index_search_timestamp(st, next_ts, flags);
+ if (!can_seek_to_key_sample(st, requested_sample, next_ts) && sample != requested_sample)
+ break;
+ timestamp = next_ts;
}
The earlier prerequisite that introduced can_seek_to_key_sample itself is FFmpeg ab77b878f1 (https://git.ffmpeg.org/gitweb/ffmpeg.git/commit/ab77b878f1, avformat/mov: fix seeking with HEVC open GOP files, 2022-05-19). The first chromium fork merge that pulled d1b96c3808 into chromium/third_party/ffmpeg is [redacted] (https://chromium.googlesource.com/chromium/third_party/ffmpeg/+/[redacted], 2024-09-20). Both the 149.0.7802.0 pin (b5e18fb9da...) and the current pin (64c21ea132...) include all of these prerequisites.
Impact
ASAN reports an out-of-bounds heap read of size 8, landing 16 bytes before the start of a 1536-byte index_entries allocation, inside the renderer process, which is sandboxed. The trigger is a <video src=...> element pointing at the crafted MP4 plus a single video.currentTime seek.
Fix
The suggested patch tightens can_seek_to_key_sample's bounds check to reject a negative sample in addition to over-large values:
--- a/third_party/ffmpeg/libavformat/mov.c
+++ b/third_party/ffmpeg/libavformat/mov.c
@@ -11598,7 +11598,8 @@ static int can_seek_to_key_sample(AVStream *st, int sample, int64_t requested_pt
if (st->codecpar->codec_id != AV_CODEC_ID_HEVC)
return 1;
- if (sample >= sc->sample_offsets_count)
+ if (sample < 0 || sample >= sti->nb_index_entries ||
+ sample >= sc->sample_offsets_count)
return 1;
key_sample_dts = sti->index_entries[sample].timestamp;
The rationale given is that sample is int and the function reads sti->index_entries[sample] and sc->sample_offsets[sample] immediately after. av_index_search_timestamp is documented to return a negative number when no matching entry exists, and the existing fix-up at mov_seek_stream:11637 only catches the first call's negative result. Rejecting sample < 0 and bounding against both nb_index_entries and sample_offsets_count at the function boundary closes the out-of-bounds read where it happens and matches the two array accesses on the next two lines.
Variants to test
- Other callers of
can_seek_to_key_sample. Any code path that passes an index fromav_index_search_timestampor another search function into this helper without a lower-bound check is a candidate. A positive result is an ASAN read before the start ofindex_entrieswhen the search returns a negative value. - Other codecs with similar key-sample logic. The guard is gated on
AV_CODEC_ID_HEVC; look for equivalent helpers for other codecs that indexindex_entriesorsample_offsetswith a signed value. A positive result is an out-of-bounds read on a crafted file of that codec. - Other
sbgp/sgpdshapes. The report shows that onesbgpentry ofcount=Ndoes not reach the retry path while N entries ofcount=1do. Try intermediate groupings and othergrouping_typevalues to see whetheropen_key_samplescan be made to contain the midpoint under different layouts. A positive result is the firstcan_seek_to_key_samplereturning 0 and the loop entering the retry path. - Unsupported tracks left in
format_context->streams[]. The report notes thatFFmpegDemuxer::OnFindStreamInfoDonelogs andcontinues past an unsupported HEVC stream without settingAVDISCARD_ALL, somov_read_seekstill walks it. Try other unsupported codecs or container combinations where a rejected stream remains in the stream list. A positive result is a seek on a supported track reaching demuxer code for the rejected track. min_sample_duration = 0files. The retry path computesnext_ts = timestamp - FFMAX(sc->min_sample_duration, 1). Files with zero-durationsttsentries are the shape that makesnext_tsfall below the first index entry. A positive result isrequested_sample = -1from the secondav_index_search_timestampcall.
What happened, in plain words
A security researcher found a bug in Chrome's built-in video handling code. When Chrome plays a video file, it does not decode the file itself from scratch: it uses a large, well-known open-source library called FFmpeg, which is bundled inside Chrome. FFmpeg knows how to read the structure of video files (the "container") and pull out the audio and video data inside.
The bug is in the part of FFmpeg that handles MP4 files. Specifically it is in the code that runs when a web page asks the video to jump to a different point in time, for example when a page sets video.currentTime. Under certain conditions, that code reads a piece of memory just before the start of an array, which is memory it is not allowed to touch. This kind of mistake is called an out-of-bounds read: the program asks for item number -1 of a list, and the computer happily hands back whatever bytes happen to sit just before the list.
The report was filed through the Chrome Vulnerability Reward Program (Chrome VRP), Google's scheme that pays people for finding and privately reporting security bugs in Chrome. It was assessed as medium severity and paid a 3000 USD reward. It was disclosed publicly on 2026-06-30. The report was submitted against the Chromium source code repository at https://chromium.googlesource.com/chromium/src.
A few terms before we go further:
- Chromium is the open-source browser project that Google Chrome is built from. Chrome adds Google-specific pieces on top, but the core code is Chromium.
- FFmpeg is a free library used by many programs to read and write audio and video. Chrome keeps its own copy of FFmpeg inside its source tree, in a folder called
third_party/ffmpeg. - libavformat is the part of FFmpeg that understands file containers (MP4, WebM and so on) and splits them into separate audio and video streams.
- A demuxer is the component that does that splitting. Think of a shipping container full of parcels: the demuxer opens the container and hands each parcel (each stream) to the right handler.
- A stream here means one continuous track inside the file, for example the video track or the audio track.
- A seek means jumping to a different playback position, like dragging the progress bar on a video player.
- A sample in this context is one small chunk of media data (roughly one frame of video or a slice of audio). Files store an index that maps timestamps to sample numbers.
- HEVC (High Efficiency Video Coding, also called H.265) is a modern video compression format. Opus is an audio compression format.
- ASAN (AddressSanitizer) is a debugging tool built into a special test build of a program. It watches every memory access and shouts loudly, with a detailed log, the moment the program reads or writes memory it should not. Researchers use ASAN builds to prove a memory bug exists.
Setup
The researcher reproduced the crash on the Linux ASAN build of Chrome 149.0.7802.0. A build is a compiled copy of the browser; an ASAN build is one compiled with the memory-checking tool switched on, so that bad memory accesses are caught and logged instead of silently doing damage.
That Chrome version pins its copy of FFmpeg to a specific revision of the chromium/third_party/ffmpeg fork (Chromium's own copy of the FFmpeg project) at commit [redacted]. A commit is a saved snapshot of the source code, identified by a long hexadecimal string; "pinning" means Chrome records exactly which snapshot it uses so builds are reproducible.
The source was also reviewed in a Chromium checkout from 2026-04-27 whose DEPS file pins third_party/ffmpeg to [redacted]. The DEPS file is a list that tells the build system which external projects (like FFmpeg) to download at which revision. The vulnerable code is present in that revision too. The file:line references in the report (for example mov.c:11604) point to that pinned FFmpeg revision. On the Chromium side, functions in ffmpeg_demuxer.cc are named rather than numbered, because line numbers shift between checkouts as code is added and removed.
The reproduction needs four attached files: poc.html (the web page that triggers the bug), poc.mp4 (the crafted video file), make_poc_mp4.py (a script that rebuilds the video file) and asan.log (the captured crash log), plus the ASAN build itself. No user gesture, autoplay opt-in or experimental feature flag is needed for the web trigger.
Finding it
The researcher identified three conditions that combine into the bug. Each one on its own is harmless; together they let a negative number reach an array lookup.
Condition 1: a bounds check that only checks the upper limit
The function can_seek_to_key_sample at third_party/ffmpeg/libavformat/mov.c:11592-11616 looks like this:
static int can_seek_to_key_sample(AVStream *st, int sample, int64_t requested_pts)
{
MOVStreamContext *sc = st->priv_data;
FFStream *const sti = ffstream(st);
int64_t key_sample_dts, key_sample_pts;
if (st->codecpar->codec_id != AV_CODEC_ID_HEVC)
return 1;
if (sample >= sc->sample_offsets_count) // sample is int, count is int — sample = -1 passes
return 1;
key_sample_dts = sti->index_entries[sample].timestamp; // line 11604: OOB read
key_sample_pts = key_sample_dts + sc->sample_offsets[sample] + sc->dts_shift;
if (is_open_key_sample(sc, sample) && key_sample_pts > requested_pts)
return 0;
return 1;
}
Line by line:
static int can_seek_to_key_sample(AVStream *st, int sample, int64_t requested_pts)declares a function that takes a stream (st), a sample number (sample, a normal signed integer) and a requested playback time (requested_pts, a 64-bit integer). It returns an integer: 1 means "yes, this sample is fine to seek to", 0 means "no, try again".MOVStreamContext *sc = st->priv_data;fetches the MP4-specific bookkeeping attached to the stream.FFStream *const sti = ffstream(st);fetches FFmpeg's internal stream structure, which holds the index of samples.int64_t key_sample_dts, key_sample_pts;declares two 64-bit integers for timestamps.if (st->codecpar->codec_id != AV_CODEC_ID_HEVC) return 1;if the stream is not HEVC video, the function does nothing special and says "fine". The bug only applies to HEVC.if (sample >= sc->sample_offsets_count) return 1;this is the only bounds check. It rejects sample numbers that are too large. Butsampleis a signed integer, so it can also be negative, and a negative number is always smaller than the count. The check lets-1through.key_sample_dts = sti->index_entries[sample].timestamp;reads the timestamp of the requested sample from the index array. Withsample = -1, this reads the element just before the start of the array. That is the out-of-bounds read, at line 11604.key_sample_pts = key_sample_dts + sc->sample_offsets[sample] + sc->dts_shift;computes the presentation timestamp (the time the frame should be shown) by adding an offset and a shift. This also indexes withsample, so it would read out of bounds too.if (is_open_key_sample(sc, sample) && key_sample_pts > requested_pts) return 0;if the sample is an "open key sample" (explained below) and its timestamp is later than the requested time, return 0, meaning "do not seek here, try again".return 1;otherwise, say "fine".
MOVStreamContext::sample_offsets_count is a signed int at third_party/ffmpeg/libavformat/isom.h:247, so the only guard rejects sample >= count and never sample < 0.
Condition 2: a retry path that forgets the safety net
The loop in mov_seek_stream at third_party/ffmpeg/libavformat/mov.c:11634-11655 is:
for (;;) {
sample = av_index_search_timestamp(st, timestamp, flags);
if (sample < 0 && sti->nb_index_entries && timestamp < sti->index_entries[0].timestamp)
sample = 0; // fix-up applies only to the first call
if (sample < 0)
return AVERROR_INVALIDDATA;
if (!sample || can_seek_to_key_sample(st, sample, timestamp))
break;
next_ts = timestamp - FFMAX(sc->min_sample_duration, 1); // crafted file: min_sample_duration = 0, so next_ts = timestamp - 1
requested_sample = av_index_search_timestamp(st, next_ts, flags);// returns -1 when no entry has ts <= next_ts
if (sample != requested_sample && !can_seek_to_key_sample(st, requested_sample, next_ts))
break; // requested_sample = -1 reaches the function with no fix-up
timestamp = next_ts;
}
Line by line:
for (;;) {starts an endless loop; it exits only viabreakorreturn.sample = av_index_search_timestamp(st, timestamp, flags);asks the index "which sample is at or before this timestamp?". This helper is documented to return a negative number when no matching entry exists.if (sample < 0 && sti->nb_index_entries && timestamp < sti->index_entries[0].timestamp) sample = 0;a safety net: if the search failed but the requested time is before the very first entry, clamp to sample 0. This only protects the first search.if (sample < 0) return AVERROR_INVALIDDATA;any other negative result is turned into an error and the seek is abandoned.if (!sample || can_seek_to_key_sample(st, sample, timestamp)) break;if the sample is 0, or the helper says it is fine, stop looping.next_ts = timestamp - FFMAX(sc->min_sample_duration, 1);otherwise, step back by one sample duration (at least 1). In the crafted file the minimum sample duration is 0, so this is simplytimestamp - 1.requested_sample = av_index_search_timestamp(st, next_ts, flags);search again for the earlier time. When no entry has a timestamp at or belownext_ts, this returns-1.if (sample != requested_sample && !can_seek_to_key_sample(st, requested_sample, next_ts)) break;if the two searches disagree and the helper says the earlier sample is not fine, stop. The problem:requested_samplecan be-1, and it is passed straight into the helper with no safety net like the one on line 3.timestamp = next_ts;move the timestamp back and loop again.
The fix-up applied after the first av_index_search_timestamp is not mirrored on requested_sample, so -1 flows directly into condition 1.
Condition 3: a crafted file that forces the retry path
The crafted MP4 forces the first can_seek_to_key_sample call to return 0, so the retry path is taken. The first av_index_search_timestamp returns a non-zero midpoint sample. For that sample, can_seek_to_key_sample evaluates is_open_key_sample(midpoint) && key_sample_pts > requested_pts; the crafted file makes both true, so the function returns 0 and the loop enters the retry path.
To understand the file, a little about MP4 internals. An MP4 file is a tree of boxes, each with a four-letter name. The moov box holds the metadata: how many samples there are, their durations, their timestamps, which ones are keyframes (frames that can be decoded on their own), and so on. The boxes named in the report are:
stts(time-to-sample): lists how long each sample lasts.ctts(composition time-to-sample): lists an offset added to each sample's decode time to get its presentation time.stss(sync sample table): lists which samples are sync samples, that is, keyframes.sgpd(sample group description): describes a group of samples, for example "these samples are sync samples of a particular kind".sbgp(sample-to-group): says which samples belong to which group described bysgpd.
make_poc_mp4.py builds a moov with stts count=4 duration=0 (so min_sample_duration = 0), ctts offsets [100,200,300,400,...] (so key_sample_pts > 0 for any midpoint), stss marking every sample sync, an sgpd of grouping_type=sync whose first entry has nal_unit_type = HEVC_NAL_CRA_NUT (21), and N separate sbgp entries each with count=1, group_description_index=1.
In plain words: every sample is marked as a keyframe; every sample has a positive presentation offset, so its presentation time is later than the requested time; and the sync group description says the group is of type "CRA" (Clean Random Access), a kind of HEVC keyframe that can be decoded but may depend on frames that come after it. That last property is what makes a sample an "open key sample".
The split-sbgp shape is required because build_open_gop_key_points at third_party/ffmpeg/libavformat/mov.c:4631-4640 uses a constant sample_id inside the inner loop and only ratchets sample_id between outer sbgp entries:
for (uint32_t i = 0; i < sc->sync_group_count; i++) {
const MOVSbgp *sg = &sc->sync_group[i];
if (sg->index == cra_index)
for (uint32_t j = 0; j < sg->count; j++)
sc->open_key_samples[k++] = sample_id; // inner loop sees a fixed sample_id
sample_id += sg->count; // ratchets only between outer entries
}
Line by line:
for (uint32_t i = 0; i < sc->sync_group_count; i++) {walks over eachsbgpentry in the file.const MOVSbgp *sg = &sc->sync_group[i];takes the current entry.if (sg->index == cra_index)checks whether this entry refers to the CRA group description.for (uint32_t j = 0; j < sg->count; j++) sc->open_key_samples[k++] = sample_id;for each sample in the entry, records the currentsample_idas an open key sample. Note thatsample_iddoes not change inside this inner loop.sample_id += sg->count;only after the inner loop finishes doessample_idadvance by the number of samples in the entry.
With one sbgp entry of count=N, open_key_samples becomes [0,0,...,0] and is_open_key_sample(midpoint) = 0, so the first can_seek_to_key_sample returns 1 and the retry path is never entered. With N per-sample sbgp entries of count=1, open_key_samples = [0,1,...,N-1], is_open_key_sample(midpoint) = 1, the first call returns 0, and the loop falls into the out-of-bounds second call. In other words, the file has to list each sample in its own sbgp entry so that the sample numbers actually count up.
Why an unsupported video track still matters
The HEVC track does not have to be supported by the Chromium media stack. On Chromium-branded builds with ENABLE_PLATFORM_HEVC=false (a build setting that turns off the platform's HEVC decoder), FFmpegDemuxerStream::Create rejects the HEVC AVStream, but FFmpegDemuxer::OnFindStreamInfoDone only logs the unsupported video track and continues from the stream-construction loop. It does not set stream->discard = AVDISCARD_ALL for that HEVC AVStream. The HEVC stream therefore remains in format_context->streams[]. When a seek is then issued for the surviving Opus track, mov_read_seek walks every stream because seek_individually defaults to 1 (third_party/ffmpeg/libavformat/mov.c:11725-11742, default at :11773), so mov_seek_stream runs on the zombie HEVC stream and reaches the bug.
In plain words: Chrome decides it cannot play the HEVC video, so it ignores it. But it forgets to tell FFmpeg to throw the track away. The track stays in FFmpeg's list of streams, like a parcel nobody wants but nobody removed from the conveyor belt. When the page seeks in the audio track, FFmpeg seeks in every stream, including the ignored video one, and that is where the bug fires.
Exploitation
Step 1: prepare the working directory
Extract poc.html, poc.mp4, make_poc_mp4.py and asan.log into an empty directory and cd into it. Download the ASAN build into the same directory so that chrome and llvm-symbolizer sit next to the PoC files. All commands below are run from that directory and every path is relative.
Why: keeping everything in one folder means the commands can use short relative paths, and the browser can find the symboliser next to it. llvm-symbolizer is a small program that turns raw memory addresses in a crash log into readable function names and line numbers.
Step 2: fetch the ASAN build
Use get_asan_chrome.py, which ships in the Chromium source tree at tools/get_asan_chrome/get_asan_chrome.py:
python3 get_asan_chrome.py --version 149.0.7802.0 --output-dir .
Line by line:
python3runs the Python 3 interpreter.get_asan_chrome.pyis the downloader script.--version 149.0.7802.0asks for that exact Chrome version, the one where the bug was reproduced.--output-dir .saves the download into the current directory (.means "here").
Unzip the resulting archive and move chrome, llvm-symbolizer and the sibling runtime files into the working directory. Why: the browser binary and its helper libraries must sit beside the PoC files so the launch command can find them.
Step 3: serve the PoC
Start a local HTTP origin from the working directory:
python3 -m http.server 8000
Line by line:
python3runs Python 3.-m http.servertells Python to run its built-in web server module.8000is the network port to listen on.
The server keeps running in that terminal; the next step uses a second terminal.
Step 4: run the ASAN build against the PoC
In another shell, launch the browser headless against poc.html:
ASAN_OPTIONS=detect_leaks=0:symbolize=1:allocator_may_return_null=1:halt_on_error=1:external_symbolizer_path=./llvm-symbolizer ./chrome --no-sandbox --user-data-dir=/tmp/asan_profile --headless=new --no-first-run --disable-breakpad --disable-crash-reporter "http://[redacted]:8000/poc.html" 2> asan.log
Line by line:
ASAN_OPTIONS=...sets environment variables that configure AddressSanitizer for this run only.detect_leaks=0turns off leak detection, which is irrelevant here and would only add noise.symbolize=1asks ASAN to translate addresses into function names.allocator_may_return_null=1lets the memory allocator return null instead of aborting when it cannot satisfy a request.halt_on_error=1stops the program at the first detected error, so the log is clean.external_symbolizer_path=./llvm-symbolizerpoints ASAN at the symboliser program in the current directory../chromeruns the browser binary from the current directory.--no-sandboxdisables Chrome's process sandbox.--user-data-dir=/tmp/asan_profileuses a throwaway profile folder so the test does not touch a real browser profile.--headless=newruns the browser without a visible window.--no-first-runskips the first-run setup screens.--disable-breakpad --disable-crash-reporterturns off Chrome's own crash reporting."http://[redacted]:8000/poc.html"is the page to load, served by the local web server from step 3.2> asan.logredirects standard error (where ASAN writes its report) into the fileasan.log.
make_poc_mp4.py is the deterministic builder for poc.mp4; running it regenerates the same 26 KB MP4 used to capture the attached asan.log. The attached log was captured with the command above. "Deterministic" means running the script again produces byte-for-byte the same file, so anyone can reproduce the exact test case.
Step 5: the web trigger
The page is <video src=poc.mp4> plus a JS video.currentTime = 0 (or any value mapping to PTS 0 on the HEVC track). No user gesture, autoplay opt-in or experimental feature flag is required.
In plain words: the page contains a video element pointing at the crafted file, and a line of JavaScript that asks the video to jump to time zero. That single seek is enough to reach the buggy code. "PTS" stands for presentation timestamp, the time at which a frame should be shown.
Crash evidence
From asan.log:
==343409==ERROR: AddressSanitizer: use-after-poison on address 0x7449f7300d70 at pc 0x59cbcbeeadcc bp 0x7299ee5992a0 sp 0x7299ee599298
READ of size 8 at 0x7449f7300d70 thread T4 (ThreadPoolForeg)
#0 0x59cbcbeeadcb in mov_seek_stream third_party/ffmpeg/libavformat/mov.c:11604:49
Line by line:
==343409==ERROR: AddressSanitizer: use-after-poison on address 0x7449f7300d70 ...ASAN reports an error at a specific memory address.use-after-poisonis ASAN's label here; the next section explains why.READ of size 8 at 0x7449f7300d70 thread T4 (ThreadPoolForeg)the program read 8 bytes at that address, on a thread namedThreadPoolForeg.#0 0x59cbcbeeadcb in mov_seek_stream third_party/ffmpeg/libavformat/mov.c:11604:49the top of the call stack: the read happened in the functionmov_seek_stream, at line 11604 ofmov.c, column 49. That is exactly the line that indexesindex_entries[sample].
Allocation context, the buffer the read is past:
0x7449f7300d70 is located 16 bytes before 1536-byte region [0x7449f7300d80,0x7449f7301380)
allocated by thread T4 (ThreadPoolForeg) here:
#0 realloc
#1 av_reallocp_array third_party/ffmpeg/libavutil/mem.c:165:11
Line by line:
0x7449f7300d70 is located 16 bytes before 1536-byte region [0x7449f7300d80,0x7449f7301380)the bad address sits 16 bytes before a 1536-byte block of memory. The block starts at0x7449f7300d80and ends at0x7449f7301380.allocated by thread T4 (ThreadPoolForeg) here:this is where that block was created.#0 reallocthe C library functionrealloc, which resizes a memory block.#1 av_reallocp_array third_party/ffmpeg/libavutil/mem.c:165:11FFmpeg's helper that resizes an array, at line 165 ofmem.c. This is theindex_entriesarray.
ASAN labels the report use-after-poison because the byte before the user region is poisoned by PartitionAlloc (Chromium's heap allocator) via __asan_poison_memory_region rather than ASAN's own malloc-shim left-redzone. The semantic is identical to heap-buffer-overflow: a read past the start of an allocation. In plain words: the byte before the allocation is marked off limits by Chromium's own allocator, PartitionAlloc, rather than by ASAN itself. ASAN sees the marked byte and calls it "poison"; the effect is the same as a classic buffer overflow.
The crashing process is the renderer, confirmed by the command line in the log's ADDITIONAL INFO block (/proc/self/exe --type=renderer ...). The renderer is the sandboxed process that runs web page code; a sandbox is an operating-system feature that limits what a process can do. The task trace shows the crash on the media demuxer seek path: media::FFmpegDemuxer::SeekInternal posts AVSeekFrame to a blocking task runner, and the out-of-bounds read fires on that runner's ThreadPoolForeg thread.
Root cause
The mistake is a missing lower bound. can_seek_to_key_sample takes sample as a signed int and immediately uses it to index sti->index_entries[sample] and sc->sample_offsets[sample], but its only guard is if (sample >= sc->sample_offsets_count). A value of -1 passes that check and the read at line 11604 lands 16 bytes before a 1536-byte index_entries buffer allocated by av_reallocp_array.
The negative value is produced legitimately: av_index_search_timestamp is documented to return a negative number when no matching entry exists. mov_seek_stream handles that for the first call with a fix-up that clamps to 0 when the timestamp precedes the first index entry, and returns AVERROR_INVALIDDATA for other negative results. The retry path added later calls av_index_search_timestamp a second time for next_ts and passes the result to can_seek_to_key_sample without any equivalent fix-up. With min_sample_duration = 0 in the crafted file, next_ts = timestamp - 1, and when no entry has a timestamp at or below next_ts, requested_sample is -1.
Bisect
A bisect is the process of finding which code change introduced a bug, by walking through the project's history. The bug landed when the retry path in mov_seek_stream was added. Before that commit the loop just decremented timestamp without making a second can_seek_to_key_sample call, so no caller ever passed a negative sample.
- Commit:
[redacted](FFmpeg upstream; carried into Chromium'schromium/third_party/ffmpegfork) - Subject:
avformat/mov: avoid seeking back to 0 on HEVC open GOP files - Date: 2024-05-21
- Upstream URL: https://git.ffmpeg.org/gitweb/ffmpeg.git/commit/[redacted]
The exact hunk that introduces the unguarded second call:
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -10133,7 +10133,7 @@ static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp,
{
MOVStreamContext *sc = st->priv_data;
FFStream *const sti = ffstream(st);
- int sample, time_sample, ret;
+ int sample, time_sample, ret, next_ts, requested_sample;
unsigned int i;
@@ -10154,7 +10154,17 @@ static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp,
if (!sample || can_seek_to_key_sample(st, sample, timestamp))
break;
- timestamp -= FFMAX(sc->min_sample_duration, 1);
+ next_ts = timestamp - FFMAX(sc->min_sample_duration, 1);
+ requested_sample = av_index_search_timestamp(st, next_ts, flags);
+ if (!can_seek_to_key_sample(st, requested_sample, next_ts) && sample != requested_sample)
+ break;
+ timestamp = next_ts;
}
Line by line:
--- a/libavformat/mov.cand+++ b/libavformat/mov.cname the file before and after the change. A diff shows removed lines with-and added lines with+.- int sample, time_sample, ret;the old declaration of local variables.+ int sample, time_sample, ret, next_ts, requested_sample;the new declaration adds two variables:next_ts(the earlier timestamp) andrequested_sample(the sample found for it).- timestamp -= FFMAX(sc->min_sample_duration, 1);the old code simply moved the timestamp back by one sample duration.+ next_ts = timestamp - FFMAX(sc->min_sample_duration, 1);the new code computes the earlier timestamp into a variable.+ requested_sample = av_index_search_timestamp(st, next_ts, flags);it then searches for a sample at that earlier time. This search can return-1.+ if (!can_seek_to_key_sample(st, requested_sample, next_ts) && sample != requested_sample) break;and it passes that result into the helper with no lower-bound check. This is the line that introduces the bug.+ timestamp = next_ts;then it continues the loop with the earlier timestamp.
The earlier prerequisite that introduced can_seek_to_key_sample itself is FFmpeg ab77b878f1 (https://git.ffmpeg.org/gitweb/ffmpeg.git/commit/ab77b878f1, avformat/mov: fix seeking with HEVC open GOP files, 2022-05-19). The first chromium fork merge that pulled d1b96c3808 into chromium/third_party/ffmpeg is [redacted] (https://chromium.googlesource.com/chromium/third_party/ffmpeg/+/[redacted], 2024-09-20). Both the 149.0.7802.0 pin (b5e18fb9da...) and the current pin (64c21ea132...) include all of these prerequisites.
Impact
ASAN reports an out-of-bounds heap read of size 8, landing 16 bytes before the start of a 1536-byte index_entries allocation, inside the renderer process, which is sandboxed. The trigger is a <video src=...> element pointing at the crafted MP4 plus a single video.currentTime seek. The report classifies the issue as memory corruption in a sandboxed process and as a crash.
In plain words: a web page can make the browser read 8 bytes of memory it should not, just by loading a video and seeking. The read happens inside the sandboxed renderer process.
Fix
The suggested patch tightens can_seek_to_key_sample's bounds check to reject a negative sample in addition to over-large values:
--- a/third_party/ffmpeg/libavformat/mov.c
+++ b/third_party/ffmpeg/libavformat/mov.c
@@ -11598,7 +11598,8 @@ static int can_seek_to_key_sample(AVStream *st, int sample, int64_t requested_pt
if (st->codecpar->codec_id != AV_CODEC_ID_HEVC)
return 1;
- if (sample >= sc->sample_offsets_count)
+ if (sample < 0 || sample >= sti->nb_index_entries ||
+ sample >= sc->sample_offsets_count)
return 1;
key_sample_dts = sti->index_entries[sample].timestamp;
Line by line:
- if (sample >= sc->sample_offsets_count)the old check only rejects too-large values.+ if (sample < 0 || sample >= sti->nb_index_entries ||the new check first rejects negative values, then rejects values beyond the number of index entries.+ sample >= sc->sample_offsets_count)and still rejects values beyond the offsets array.return 1;in any of those cases, the function says "fine" and does not touch the arrays.key_sample_dts = sti->index_entries[sample].timestamp;the read only happens when the sample number is valid for both arrays.
The rationale given is that sample is int and the function reads sti->index_entries[sample] and sc->sample_offsets[sample] immediately after. av_index_search_timestamp is documented to return a negative number when no matching entry exists, and the existing fix-up at mov_seek_stream:11637 only catches the first call's negative result. Rejecting sample < 0 and bounding against both nb_index_entries and sample_offsets_count at the function boundary closes the out-of-bounds read where it happens and matches the two array accesses on the next two lines.
Variants to test
These are follow-up ideas for other researchers, each with a way to tell whether it worked.
- Other callers of
can_seek_to_key_sample. Any code path that passes an index fromav_index_search_timestampor another search function into this helper without a lower-bound check is a candidate. A positive result is an ASAN read before the start ofindex_entrieswhen the search returns a negative value. - Other codecs with similar key-sample logic. The guard is gated on
AV_CODEC_ID_HEVC; look for equivalent helpers for other codecs that indexindex_entriesorsample_offsetswith a signed value. A positive result is an out-of-bounds read on a crafted file of that codec. - Other
sbgp/sgpdshapes. The report shows that onesbgpentry ofcount=Ndoes not reach the retry path while N entries ofcount=1do. Try intermediate groupings and othergrouping_typevalues to see whetheropen_key_samplescan be made to contain the midpoint under different layouts. A positive result is the firstcan_seek_to_key_samplereturning 0 and the loop entering the retry path. - Unsupported tracks left in
format_context->streams[]. The report notes thatFFmpegDemuxer::OnFindStreamInfoDonelogs andcontinues past an unsupported HEVC stream without settingAVDISCARD_ALL, somov_read_seekstill walks it. Try other unsupported codecs or container combinations where a rejected stream remains in the stream list. A positive result is a seek on a supported track reaching demuxer code for the rejected track. min_sample_duration = 0files. The retry path computesnext_ts = timestamp - FFMAX(sc->min_sample_duration, 1). Files with zero-durationsttsentries are the shape that makesnext_tsfall below the first index entry. A positive result isrequested_sample = -1from the secondav_index_search_timestampcall.
Glossary
- API: an agreed way for one piece of software to ask another to do something, like a menu of functions with fixed names and inputs.
- ASAN (AddressSanitizer): a debugging tool that watches memory accesses and reports any read or write outside the memory a program is allowed to touch.
- AVStream: FFmpeg's structure describing one stream (one track) inside a media file.
- Bisect: finding the code change that introduced a bug by walking through the project's history.
- Buffer: a block of memory set aside to hold data, such as an array of entries.
- Build: a compiled copy of a program, produced from source code.
- Chrome VRP (Chrome Vulnerability Reward Program): Google's scheme that pays researchers for privately reporting security bugs in Chrome.
- Chromium: the open-source browser project that Google Chrome is built from.
- Commit: a saved snapshot of a source code repository, identified by a long hexadecimal string.
- Container (media): a file format such as MP4 that holds audio and video streams together with metadata.
- CRA (Clean Random Access): a kind of HEVC keyframe that can be decoded on its own but may depend on frames that come after it.
- ctts: the MP4 box that stores presentation-time offsets for samples.
- DEPS file: a list telling the build system which external projects to download at which revisions.
- Demuxer: the component that opens a media container and splits it into separate streams.
- Diff: a display of changes between two versions of a file, with removed lines marked
-and added lines marked+. - FFmpeg: a widely used open-source library for reading and writing audio and video.
- Heap: the area of memory a program uses for data it creates while running, as opposed to fixed-size stack memory.
- HEVC (H.265): a modern video compression format.
- Keyframe (sync sample): a frame that can be decoded on its own, without needing earlier frames.
- libavformat: the part of FFmpeg that handles media containers and streams.
- llvm-symbolizer: a helper program that turns raw memory addresses in a crash log into function names and line numbers.
- moov: the MP4 box that holds the file's metadata: sample counts, durations, timestamps and keyframe lists.
- MP4: a common media container format.
- Opus: an audio compression format.
- Out-of-bounds read: reading memory outside the region a program is allowed to access, for example item -1 of an array.
- PartitionAlloc: Chromium's own memory allocator, which marks memory around allocations as off limits.
- Pinning: recording exactly which revision of an external project a build uses, so builds are reproducible.
- PTS (presentation timestamp): the time at which a frame should be shown.
- Renderer: the sandboxed browser process that runs web page code.
- Sample: one small chunk of media data, roughly a frame of video or a slice of audio.
- Sandbox: an operating-system feature that limits what a process can do, containing the damage from bugs.
- sbgp: the MP4 box that maps samples to a sample group described by
sgpd. - Seek: jumping to a different playback position in a media file.
- sgpd: the MP4 box that describes a sample group, for example a group of sync samples.
- stss: the MP4 box listing which samples are sync samples (keyframes).
- stts: the MP4 box listing how long each sample lasts.
- Stream: one continuous track inside a media file, such as the video track or the audio track.
- use-after-poison: ASAN's label when a program touches memory that has been deliberately marked off limits, here by Chromium's allocator rather than ASAN itself.