From 491210ac1207239292181c31fdaf1b5b00fb48c2 Mon Sep 17 00:00:00 2001 From: Deluan Date: Thu, 20 Mar 2025 12:39:40 -0400 Subject: [PATCH] fix(scanner): ignore NaN ReplayGain values Fix: https://github.com/navidrome/navidrome/issues/3858 Signed-off-by: Deluan --- model/metadata/metadata.go | 2 +- model/metadata/metadata_test.go | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/model/metadata/metadata.go b/model/metadata/metadata.go index 3d5d64dd1..471c2434c 100644 --- a/model/metadata/metadata.go +++ b/model/metadata/metadata.go @@ -120,7 +120,7 @@ func (md Metadata) first(key model.TagName) string { func float(value string, def ...float64) float64 { v, err := strconv.ParseFloat(value, 64) - if err != nil || v == math.Inf(-1) || v == math.Inf(1) { + if err != nil || v == math.Inf(-1) || math.IsInf(v, 1) || math.IsNaN(v) { if len(def) > 0 { return def[0] } diff --git a/model/metadata/metadata_test.go b/model/metadata/metadata_test.go index f3478ccba..5d9c4a3ed 100644 --- a/model/metadata/metadata_test.go +++ b/model/metadata/metadata_test.go @@ -264,6 +264,7 @@ var _ = Describe("Metadata", func() { Entry("1.2dB", "1.2dB", 1.2), Entry("Infinity", "Infinity", 0.0), Entry("Invalid value", "INVALID VALUE", 0.0), + Entry("NaN", "NaN", 0.0), ) DescribeTable("Peak", func(tagValue string, expected float64) { @@ -275,6 +276,7 @@ var _ = Describe("Metadata", func() { Entry("Invalid dB suffix", "0.7dB", 1.0), Entry("Infinity", "Infinity", 1.0), Entry("Invalid value", "INVALID VALUE", 1.0), + Entry("NaN", "NaN", 1.0), ) DescribeTable("getR128GainValue", func(tagValue string, expected float64) {