From e00e7802c83ac6c7bf05057acbf4080b007604cc Mon Sep 17 00:00:00 2001
From: Max Kellermann <max.kellermann@gmail.com>
Date: Fri, 12 Jul 2024 16:09:28 +0200
Subject: [PATCH] decoder/mpg123: report unknown duration if mpg123_length()<0

Closes https://github.com/MusicPlayerDaemon/MPD/issues/2058
---
 src/decoder/plugins/Mpg123DecoderPlugin.cxx | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/decoder/plugins/Mpg123DecoderPlugin.cxx b/src/decoder/plugins/Mpg123DecoderPlugin.cxx
index a3f7d895f..bcce84b04 100644
--- a/src/decoder/plugins/Mpg123DecoderPlugin.cxx
+++ b/src/decoder/plugins/Mpg123DecoderPlugin.cxx
@@ -248,6 +248,8 @@ static SignedSongTime
 GetDuration(mpg123_handle &handle, const AudioFormat &audio_format) noexcept
 {
 	const off_t num_samples = mpg123_length(&handle);
+	if (num_samples < 0)
+		return SignedSongTime::Negative();
 
 	return SongTime::FromScale<uint64_t>(num_samples,
 					     audio_format.sample_rate);