git: 910c4d572da2 - 2024Q2 - audio/rsgain: Fix segmentation fault

From: Jason E. Hale <jhale_at_FreeBSD.org>
Date: Thu, 16 May 2024 00:04:47 UTC
The branch 2024Q2 has been updated by jhale:

URL: https://cgit.FreeBSD.org/ports/commit/?id=910c4d572da2fcc17dc9d646136dfb6d6e9fdcc4

commit 910c4d572da2fcc17dc9d646136dfb6d6e9fdcc4
Author:     Jason E. Hale <jhale@FreeBSD.org>
AuthorDate: 2024-05-15 23:56:38 +0000
Commit:     Jason E. Hale <jhale@FreeBSD.org>
CommitDate: 2024-05-16 00:04:35 +0000

    audio/rsgain: Fix segmentation fault
    
    When calculating album loudness on a drectory containing one or more
    audio files using `rsgain easy .`, for example, a segmentation fault
    can occur.
    
    Affects versions 3.4 and 3.5.
    
    PR:             278838
    Reported by:    <pere_goriot99@yahoo.com>
    MFH:            2024Q2
    
    (cherry picked from commit 99bafb68144c1824441d3b47c3dc141c7721148b)
---
 audio/rsgain/Makefile                 |  1 +
 audio/rsgain/files/patch-src_scan.cpp | 16 ++++++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/audio/rsgain/Makefile b/audio/rsgain/Makefile
index 77f2e7f5f933..0c4d8bd4aa04 100644
--- a/audio/rsgain/Makefile
+++ b/audio/rsgain/Makefile
@@ -1,5 +1,6 @@
 PORTNAME=	rsgain
 DISTVERSION=	3.5
+PORTREVISION=	1
 DISTVERSIONSUFFIX=	-source
 CATEGORIES=	audio
 MASTER_SITES=	https://github.com/complexlogic/rsgain/releases/download/v${DISTVERSION}/
diff --git a/audio/rsgain/files/patch-src_scan.cpp b/audio/rsgain/files/patch-src_scan.cpp
new file mode 100644
index 000000000000..3d9dbb23b23f
--- /dev/null
+++ b/audio/rsgain/files/patch-src_scan.cpp
@@ -0,0 +1,16 @@
+Fix a segfault when calculating album loudness.
+
+PR: 278838
+Regressed by: https://github.com/complexlogic/rsgain/commit/63e87a4f7d3b5c816eab630fba41ba9a63b82519
+
+--- src/scan.cpp.orig	2024-02-25 17:47:20 UTC
++++ src/scan.cpp
+@@ -639,7 +639,7 @@ void ScanJob::calculate_album_loudness() 
+     std::vector<ebur128_state*> states(nb_states);
+     for (const Track &track : tracks)
+         if (track.result.track_loudness != -HUGE_VAL)
+-            states.emplace_back(track.ebur128.get());
++            states[(size_t) (&track - &tracks[0])] = track.ebur128.get();
+ 
+     if (ebur128_loudness_global_multiple(states.data(), states.size(), &album_loudness) != EBUR128_SUCCESS)
+         album_loudness = config.target_loudness;