From 8a7577c9bfc743425a337261ccc48f9b7cfe5cb2 Mon Sep 17 00:00:00 2001 From: WithoutPants <53250216+WithoutPants@users.noreply.github.com> Date: Tue, 3 Aug 2021 14:29:57 +1000 Subject: [PATCH] Fix inf values causing marshal error (#1607) --- pkg/api/resolver_model_scene.go | 4 ++-- pkg/api/types.go | 12 ++++++++++++ ui/v2.5/src/components/Changelog/versions/v090.md | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/pkg/api/resolver_model_scene.go b/pkg/api/resolver_model_scene.go index 89f1ed8ae..5d909f6b5 100644 --- a/pkg/api/resolver_model_scene.go +++ b/pkg/api/resolver_model_scene.go @@ -67,12 +67,12 @@ func (r *sceneResolver) File(ctx context.Context, obj *models.Scene) (*models.Sc bitrate := int(obj.Bitrate.Int64) return &models.SceneFileType{ Size: &obj.Size.String, - Duration: &obj.Duration.Float64, + Duration: handleFloat64(obj.Duration.Float64), VideoCodec: &obj.VideoCodec.String, AudioCodec: &obj.AudioCodec.String, Width: &width, Height: &height, - Framerate: &obj.Framerate.Float64, + Framerate: handleFloat64(obj.Framerate.Float64), Bitrate: &bitrate, }, nil } diff --git a/pkg/api/types.go b/pkg/api/types.go index f786c3968..9af592806 100644 --- a/pkg/api/types.go +++ b/pkg/api/types.go @@ -1,7 +1,19 @@ package api +import "math" + // An enum https://golang.org/ref/spec#Iota const ( create = iota // 0 update = iota // 1 ) + +// #1572 - Inf and NaN values cause the JSON marshaller to fail +// Return nil for these values +func handleFloat64(v float64) *float64 { + if math.IsInf(v, 0) || math.IsNaN(v) { + return nil + } + + return &v +} diff --git a/ui/v2.5/src/components/Changelog/versions/v090.md b/ui/v2.5/src/components/Changelog/versions/v090.md index b03c020e7..f7812419d 100644 --- a/ui/v2.5/src/components/Changelog/versions/v090.md +++ b/ui/v2.5/src/components/Changelog/versions/v090.md @@ -6,6 +6,7 @@ * Added de-DE language option. ([#1578](https://github.com/stashapp/stash/pull/1578)) ### 🐛 Bug fixes +* Fix infinity framerate values causing resolver error. ([#1607](https://github.com/stashapp/stash/pull/1607)) * Fix unsetting performer gender not working correctly. ([#1606](https://github.com/stashapp/stash/pull/1606)) * Fix is missing date scene criterion causing invalid SQL. ([#1577](https://github.com/stashapp/stash/pull/1577)) * Fix rendering of carousel images on Apple devices. ([#1562](https://github.com/stashapp/stash/pull/1562))