From 2b024ec1b4cbed31678bbb8da3ef0f8145f9953e Mon Sep 17 00:00:00 2001 From: Jonathan Matthew Date: Fri, 28 Aug 2020 07:53:26 +1000 Subject: [PATCH] modplug: avoid division by zero Under some conditions, GetMaxPosition() returns zero, which should cause position queries to fail rather than crash. --- ext/modplug/gstmodplug.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ext/modplug/gstmodplug.cc b/ext/modplug/gstmodplug.cc index 30c5952ab2..af6de488bb 100644 --- a/ext/modplug/gstmodplug.cc +++ b/ext/modplug/gstmodplug.cc @@ -298,11 +298,15 @@ gst_modplug_src_query (GstPad * pad, GstObject * parent, GstQuery * query) gst_query_parse_position (query, &format, NULL); if (format == GST_FORMAT_TIME) { gint64 pos; + guint32 max; - pos = (modplug->song_length * modplug->mSoundFile->GetCurrentPos ()); - pos /= modplug->mSoundFile->GetMaxPosition (); - gst_query_set_position (query, format, pos); - res = TRUE; + max = modplug->mSoundFile->GetMaxPosition(); + if (max > 0) { + pos = (modplug->song_length * modplug->mSoundFile->GetCurrentPos ()) / + max; + gst_query_set_position (query, format, pos); + res = TRUE; + } } } break;