From f242f0631b19e4fbb9991ca07c246a1c12af9615 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Tue, 20 Mar 2018 18:01:35 +0200 Subject: [PATCH] Fixed crash in when MP3 length guesstimation failed https://forum.zdoom.org/viewtopic.php?t=59881 --- src/sound/musicformats/music_libsndfile.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sound/musicformats/music_libsndfile.cpp b/src/sound/musicformats/music_libsndfile.cpp index b87492a4e..3a44d9f56 100644 --- a/src/sound/musicformats/music_libsndfile.cpp +++ b/src/sound/musicformats/music_libsndfile.cpp @@ -298,8 +298,9 @@ SndFileSong::SndFileSong(FileReader &reader, SoundDecoder *decoder, uint32_t loo if (!startass) loop_start = Scale(loop_start, SampleRate, 1000); if (!endass) loop_end = Scale(loop_end, SampleRate, 1000); + const uint32_t sampleLength = (uint32_t)decoder->getSampleLength(); Loop_Start = loop_start; - Loop_End = clamp(loop_end, 0, (uint32_t)decoder->getSampleLength()); + Loop_End = sampleLength == 0 ? loop_end : clamp(loop_end, 0, sampleLength); Reader = std::move(reader); Decoder = decoder; Channels = iChannels == ChannelConfig_Stereo? 2:1;