command: avoid division by zero in av_timecode_make_string()

`av_timecode_make_string()` divides by fps unconditionally. And
 relying on container_fps always carrying a meaningful value was
 misguided. So we now check that fps is non-zero before calling that
 function.

 Issue encountered with a couple of old FLV files triggering a segfault.

Signed-off-by: Mohammad AlSaleh <CE.Mohammad.AlSaleh@gmail.com>
This commit is contained in:
Mohammad AlSaleh 2024-10-08 05:48:00 +03:00 committed by Kacper Michajłow
parent 2ac1d6db32
commit 28a4e19a67
1 changed files with 13 additions and 8 deletions

View File

@ -2541,15 +2541,20 @@ static int mp_property_video_frame_info(void *ctx, struct m_property *prop,
char approx_smpte[AV_TIMECODE_STR_SIZE] = {0};
if (s12m_tc[0] == '\0' && mpctx->vo_chain) {
unsigned container_fps = lrint(mpctx->vo_chain->filter->container_fps);
// Avoid division-by-zero in av_timecode_make_string() if reported
// container_fps is or rounds to 0.
if (container_fps) {
const AVTimecode tcr = {
.start = 0,
.flags = AV_TIMECODE_FLAG_DROPFRAME,
.rate = av_d2q(mpctx->vo_chain->filter->container_fps, INT_MAX),
.fps = lrint(mpctx->vo_chain->filter->container_fps),
.fps = container_fps,
};
int frame = lrint(get_current_pos_ratio(mpctx, false) * get_frame_count(mpctx));
av_timecode_make_string(&tcr, approx_smpte, frame);
}
}
struct m_sub_property props[] = {
{"picture-type", SUB_PROP_STR(pict_type), .unavailable = !pict_type},