Package: xmms2
Version: 0.8+dfsg-21
Severity: important
Tags: patch upstream

Dear Maintainer,

After finally doing a long procrastinated dist-upgrade, i am no longer able
to play streams.

I am running into the following:
21:23:55  INFO: ../src/xmms/xform.c:1363: Successfully setup chain for 
'https://nightride.fm/stream/nightride.mp3' (39865) containing 
curl:magic:mad:converter:segment
21:23:56  FAIL: xmms_curl_callback_write: assertion '(data->bufferlen + len) <= 
CURL_MAX_WRITE_SIZE' failed
21:23:56 ERROR: ../src/plugins/curl/curl_http.c:378: Curl fill_buffer returned 
error: (23) Failed writing received data to disk/application

While this is caused by a discrepancy between the design of xmms2 and/or the
xmms2 curl plugin, and the design of libcurl, the attached patch bumps the
intermediate buffer size to a point where the issue should no longer occur.

-- System Information:
Debian Release: 11.3
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable-security'), (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 5.10.0-13-amd64 (SMP w/8 CPU threads)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.utf8 (charmap=UTF-8), LANGUAGE=en_US:en
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages xmms2 depends on:
ii  xmms2-client-cli                          0.8+dfsg-21
ii  xmms2-core                                0.8+dfsg-21
ii  xmms2-icon                                0.8+dfsg-21
ii  xmms2-plugin-alsa [xmms2-plugin-output]   0.8+dfsg-21
ii  xmms2-plugin-ao [xmms2-plugin-output]     0.8+dfsg-21
ii  xmms2-plugin-ices [xmms2-plugin-output]   0.8+dfsg-21
ii  xmms2-plugin-id3v2                        0.8+dfsg-21
ii  xmms2-plugin-jack [xmms2-plugin-output]   0.8+dfsg-21
ii  xmms2-plugin-mad                          0.8+dfsg-21
ii  xmms2-plugin-oss [xmms2-plugin-output]    0.8+dfsg-21
ii  xmms2-plugin-pulse [xmms2-plugin-output]  0.8+dfsg-21
ii  xmms2-plugin-vorbis                       0.8+dfsg-21

xmms2 recommends no packages.

xmms2 suggests no packages.

-- no debconf information
>From 7f7c64ac116e119851f13237d0c68d3ca0ce3343 Mon Sep 17 00:00:00 2001
From: Luc Verhaegen <l...@skynet.be>
Date: Thu, 7 Apr 2022 11:53:17 +0200
Subject: [PATCH 1/1] curl: set intermediate buffer to 128kB

This is pretty arbitrary, but larger than it used to be.

Curl expects us to immediately handle the data it sends over. We instead go
and copy the received data into an intermediate buffer, so our own
callback can then later copy it into the final buffer.

The intermediate buffer used to be set to CURL_MAX_WRITE_SIZE (16kB),
which is getting overrun.

Since we use an intermediate buffer, setting CURLOPT_BUFFERSIZE has no
effect for us.

There is no logic, no science to this, but at least 128kB should be large
enough to store a full second of a FLAC stream.

Signed-off-by: Luc Verhaegen <l...@skynet.be>
---
 src/plugins/curl/curl_http.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/plugins/curl/curl_http.c b/src/plugins/curl/curl_http.c
index f19b6d94..d0c9e1f1 100644
--- a/src/plugins/curl/curl_http.c
+++ b/src/plugins/curl/curl_http.c
@@ -31,6 +31,7 @@
 /*
  * Type definitions
  */
+#define XMMS2_CURL_BUFFER_SIZE 0x200000
 
 typedef struct {
        CURL *curl_easy;
@@ -212,7 +213,7 @@ xmms_curl_init (xmms_xform_t *xform)
        g_snprintf (proxyuserpass, sizeof (proxyuserpass), "%s:%s", proxyuser,
                    proxypass);
 
-       data->buffer = g_malloc (CURL_MAX_WRITE_SIZE);
+       data->buffer = g_malloc (XMMS2_CURL_BUFFER_SIZE);
        data->url = g_strdup (url);
 
        /* check for broken version of curl here */
@@ -463,7 +464,7 @@ xmms_curl_callback_write (void *ptr, size_t size, size_t 
nmemb, void *stream)
 
        len = size * nmemb;
 
-       g_return_val_if_fail ((data->bufferlen + len) <= CURL_MAX_WRITE_SIZE, 
0);
+       g_return_val_if_fail ((data->bufferlen + len) <= 
XMMS2_CURL_BUFFER_SIZE, 0);
 
        memcpy (data->buffer + data->bufferlen, ptr, len);
        data->bufferlen = data->bufferlen + len;
-- 
2.30.2

Reply via email to