stts entries with sample_duration == 0 are accepted by the parser.
If such an entry is processed while current_dts > corrected_dts,
which can happen after a clipped negative-delta entry leaves residual
drift, and drift evaluates to 0, the expression
sc->stts_data[i].duration - 1
computes 0 - 1 on an unsigned value and wraps around to UINT32_MAX.
The bogus correction is then subtracted from current_dts and wraps the
stored stts duration.
Compute the correction as FFMAX(duration, 1) - 1 instead: a zero
duration maps to a correction of 0, positive durations are unchanged.
Reproduced with a minimal mp4 carrying the stts entries
{sample_count 1, sample_duration 0xFFFFFFFF} and
{sample_count 8, sample_duration 0}, parsed by a build instrumented
with -fsanitize=unsigned-integer-overflow:
libavformat/mov.c:3917:107: runtime error: unsigned integer
overflow: 0 - 1 cannot be represented in type 'unsigned int'
Signed-off-by: sucloudflare <[email protected]>
Signed-off-by: sucloudflare <[email protected]>
---
libavformat/mov.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 0c2f592e7f..9e21001d35 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -3914,7 +3914,7 @@ static int mov_read_stts(MOVContext *c, AVIOContext *pb,
MOVAtom atom)
if (current_dts > corrected_dts) {
int64_t drift = av_sat_sub64(current_dts, corrected_dts) /
FFMAX(sample_count, 1);
- uint32_t correction = (sc->stts_data[i].duration > drift) ? drift
: sc->stts_data[i].duration - 1;
+ uint32_t correction = (sc->stts_data[i].duration > drift) ? drift
: FFMAX(sc->stts_data[i].duration, 1) - 1;
current_dts -= correction * (uint64_t)sample_count;
sc->stts_data[i].duration -= correction;
}
--
2.47.3
_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]