From 2afe427ab382b18135d57c5a1414d6d6a3eaa1a2 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 8 Aug 2022 19:20:52 +0200 Subject: [PATCH] output/httpd: copy from returned encoder buffer This fixes a regression from commits c266fb77581 and 00b8ced09f6, but really caused by API change in commit 7e14f8f8300f, and this plugin's failure to adapt to this API change. Closes https://github.com/MusicPlayerDaemon/MPD/issues/1585 --- src/output/plugins/httpd/HttpdOutputPlugin.cxx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/output/plugins/httpd/HttpdOutputPlugin.cxx b/src/output/plugins/httpd/HttpdOutputPlugin.cxx index ed35c1934..fa88bdda3 100644 --- a/src/output/plugins/httpd/HttpdOutputPlugin.cxx +++ b/src/output/plugins/httpd/HttpdOutputPlugin.cxx @@ -161,12 +161,21 @@ HttpdOutput::ReadPage() noexcept size_t size = 0; do { - const auto r = encoder->Read(std::span{buffer}.subspan(size)); + const auto b = std::span{buffer}.subspan(size); + const auto r = encoder->Read(b); if (r.empty()) break; unflushed_input = 0; + if (r.data() != b.data()) { + /* if the encoder did not write to the given + buffer but instead returned its own buffer, + we need to copy it so we have a contiguous + buffer */ + std::copy(r.begin(), r.end(), b.begin()); + } + size += r.size(); } while (size < sizeof(buffer));