[FFmpeg-cvslog] avformat/mov: compute absolute dts difference without overflow in mov_find_next_sample()
Michael Niedermayer
git at videolan.org
Sun Apr 14 23:58:29 EEST 2024
ffmpeg | branch: release/3.4 | Michael Niedermayer <michael at niedermayer.cc> | Sat Sep 30 21:04:11 2023 +0200| [9d73eb002fb05ec7304b897fcb3e670696e43552] | committer: Michael Niedermayer
avformat/mov: compute absolute dts difference without overflow in mov_find_next_sample()
Fixes: signed integer overflow: -9223372036854775808 - 9222726413022000000 cannot be represented in type 'long'
Fixes: 51896/clusterfuzz-testcase-minimized-ffmpeg_dem_MOV_fuzzer-5959420033761280
Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
(cherry picked from commit 3508b496e195440d0af0203e2822937b8c6f5598)
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=9d73eb002fb05ec7304b897fcb3e670696e43552
---
libavformat/mov.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 4b9e83de44..76fddf04eb 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -6543,12 +6543,13 @@ static AVIndexEntry *mov_find_next_sample(AVFormatContext *s, AVStream **st)
if (msc->pb && msc->current_sample < avst->nb_index_entries) {
AVIndexEntry *current_sample = &avst->index_entries[msc->current_sample];
int64_t dts = av_rescale(current_sample->timestamp, AV_TIME_BASE, msc->time_scale);
+ uint64_t dtsdiff = best_dts > dts ? best_dts - (uint64_t)dts : ((uint64_t)dts - best_dts);
av_log(s, AV_LOG_TRACE, "stream %d, sample %d, dts %"PRId64"\n", i, msc->current_sample, dts);
if (!sample || (!(s->pb->seekable & AVIO_SEEKABLE_NORMAL) && current_sample->pos < sample->pos) ||
((s->pb->seekable & AVIO_SEEKABLE_NORMAL) &&
((msc->pb != s->pb && dts < best_dts) || (msc->pb == s->pb && dts != AV_NOPTS_VALUE &&
- ((FFABS(best_dts - dts) <= AV_TIME_BASE && current_sample->pos < sample->pos) ||
- (FFABS(best_dts - dts) > AV_TIME_BASE && dts < best_dts)))))) {
+ ((dtsdiff <= AV_TIME_BASE && current_sample->pos < sample->pos) ||
+ (dtsdiff > AV_TIME_BASE && dts < best_dts)))))) {
sample = current_sample;
best_dts = dts;
*st = avst;
More information about the ffmpeg-cvslog
mailing list