From e7ccf5d8ad8a9812c15bb0331776fb22edf47893 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 26 Jun 2023 12:24:17 +0400 Subject: [PATCH] Fix possible std::clamp contract violation. --- .../media/streaming/media_streaming_utility.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/media/streaming/media_streaming_utility.cpp b/Telegram/SourceFiles/media/streaming/media_streaming_utility.cpp index 5b3ac86dd..fdfbe20f8 100644 --- a/Telegram/SourceFiles/media/streaming/media_streaming_utility.cpp +++ b/Telegram/SourceFiles/media/streaming/media_streaming_utility.cpp @@ -28,7 +28,12 @@ crl::time FramePosition(const Stream &stream) { : (stream.decodedFrame->pts != AV_NOPTS_VALUE) ? stream.decodedFrame->pts : stream.decodedFrame->pkt_dts; - return FFmpeg::PtsToTime(pts, stream.timeBase); + const auto result = FFmpeg::PtsToTime(pts, stream.timeBase); + + // Sometimes the result here may be larger than the stream duration. + return (stream.duration == kDurationUnavailable) + ? result + : std::min(result, stream.duration); } FFmpeg::AvErrorWrap ProcessPacket(Stream &stream, FFmpeg::Packet &&packet) {