Skip to content

Commit cba47ef

Browse files
committed
libldac-dec: fix ldacBT_init_handle_decode channel config
The decoder init passes UNSET (-1) as channel_config_index to ldaclib_set_config_info because the struct fields are assigned after the call instead of before. Fails with LDAC_ERR_ASSERT_CHANNEL_CONFIG (533) on every invocation. This breaks LDAC A2DP in PipeWire: codec_init fails, the bluetooth sink never starts, and all streams routed to it stay stuck in [init] with no audio and no user-visible error. Upstream PR: O2C14/libldac-dec#2
1 parent a1a6c3a commit cba47ef

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
From 1c76d1d65e6da0a63b8bc9329debcf2ff1516143 Mon Sep 17 00:00:00 2001
2+
From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= <joerg@thalheim.io>
3+
Date: Mon, 30 Mar 2026 11:40:28 +0200
4+
Subject: [PATCH] Fix use-before-init in ldacBT_init_handle_decode
5+
MIME-Version: 1.0
6+
Content-Type: text/plain; charset=UTF-8
7+
Content-Transfer-Encoding: 8bit
8+
9+
ldacBT_close_handle() resets cci/frmlen/frm_status to UNSET (-1).
10+
The subsequent ldaclib_set_config_info() was called with these stale
11+
struct members instead of the freshly computed local values, causing
12+
LDAC_ERR_ASSERT_CHANNEL_CONFIG (533) on every invocation regardless
13+
of the channel mode passed in.
14+
15+
Move the struct assignments before the ldaclib_set_config_info() call
16+
so it receives valid configuration.
17+
18+
This was breaking LDAC A2DP in PipeWire: the decoder handle fails to
19+
initialise during codec_init(), which aborts the entire codec setup
20+
and leaves the bluetooth sink unable to start.
21+
22+
Signed-off-by: Jörg Thalheim <joerg@thalheim.io>
23+
---
24+
src/ldacBT_api.o.c | 9 ++++-----
25+
1 file changed, 4 insertions(+), 5 deletions(-)
26+
27+
diff --git a/src/ldacBT_api.o.c b/src/ldacBT_api.o.c
28+
index f4cb9cd..a396a14 100644
29+
--- a/src/ldacBT_api.o.c
30+
+++ b/src/ldacBT_api.o.c
31+
@@ -165,6 +165,10 @@ LDACBT_API int ldacBT_init_handle_decode(
32+
// tbl_ldacbt_config[0].frmlen_1ch;
33+
// frmlen = 165 * channel - LDACBT_FRMHDRBYTES;
34+
frmlen = tbl_ldacbt_config[0].frmlen_1ch * channel - LDACBT_FRMHDRBYTES;
35+
+ hLdacBT->frmlen = frmlen;
36+
+ hLdacBT->cm = cm;
37+
+ hLdacBT->cci = cci;
38+
+ hLdacBT->frm_status = 0;
39+
/* Set Configuration Information */
40+
result = ldaclib_set_config_info(
41+
hLdacBT->hLDAC, hLdacBT->sfid, hLdacBT->cci, hLdacBT->frmlen, hLdacBT->frm_status);
42+
@@ -174,11 +178,6 @@ LDACBT_API int ldacBT_init_handle_decode(
43+
} else if (result != LDAC_S_OK) {
44+
hLdacBT->error_code_api = LDACBT_GET_LDACLIB_ERROR_CODE;
45+
}
46+
- hLdacBT->frmlen = frmlen;
47+
- hLdacBT->cm = cm;
48+
- hLdacBT->cci = cci;
49+
- hLdacBT->frm_status = 0;
50+
- hLdacBT->sfid = sfid;
51+
result = ldaclib_init_decode(hLdacBT->hLDAC, nshift);
52+
if (LDAC_FAILED(result)) {
53+
hLdacBT->error_code_api = LDACBT_GET_LDACLIB_ERROR_CODE;
54+
--
55+
2.53.0
56+

pkgs/by-name/li/libldac-dec/package.nix

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ stdenv.mkDerivation {
1717
hash = "sha256-pdeEtQXxL2pd9qTfLOEmPDn3POgo5qxRqbK807WN98s=";
1818
};
1919

20+
patches = [
21+
# ldacBT_init_handle_decode passes UNSET (-1) cci/frmlen to
22+
# ldaclib_set_config_info, failing with LDAC_ERR_ASSERT_CHANNEL_CONFIG
23+
# on every call. Breaks LDAC A2DP in pipewire.
24+
# https://github.com/O2C14/libldac-dec/pull/2
25+
./fix-init-decode.patch
26+
];
27+
2028
nativeBuildInputs = [ cmake ];
2129

2230
# Upstream CMakeLists.txt doesn't have install rules

0 commit comments

Comments
 (0)