From b7a99b4a4baa42b5dd09d598741e8438e611f988 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Thu, 11 Jun 2020 06:28:56 +0200
Subject: [PATCH 1/6] increment version number to 0.21.25

---
 NEWS                        | 2 ++
 android/AndroidManifest.xml | 4 ++--
 doc/conf.py                 | 2 +-
 meson.build                 | 2 +-
 4 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/NEWS b/NEWS
index 203b1fef2..2b5a446de 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,5 @@
+ver 0.21.25 (not yet released)
+
 ver 0.21.24 (2020/06/10)
 * protocol
   - "tagtypes" requires no permissions
diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml
index bde283bce..e2a31db83 100644
--- a/android/AndroidManifest.xml
+++ b/android/AndroidManifest.xml
@@ -2,8 +2,8 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
           package="org.musicpd"
           android:installLocation="auto"
-          android:versionCode="47"
-          android:versionName="0.21.24">
+          android:versionCode="48"
+          android:versionName="0.21.25">
 
   <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28"/>
 
diff --git a/doc/conf.py b/doc/conf.py
index c76f391da..4c3b663fa 100644
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -38,7 +38,7 @@ author = 'Max Kellermann'
 # built documents.
 #
 # The short X.Y version.
-version = '0.21.24'
+version = '0.21.25'
 # The full version, including alpha/beta/rc tags.
 release = version
 
diff --git a/meson.build b/meson.build
index 6ec4cb5fe..a9eb92798 100644
--- a/meson.build
+++ b/meson.build
@@ -1,7 +1,7 @@
 project(
   'mpd',
   ['c', 'cpp'],
-  version: '0.21.24',
+  version: '0.21.25',
   meson_version: '>= 0.49.0',
   default_options: [
     'c_std=c99',

From 5716cde1fbf027b1270179dcae700b3b974b1966 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Thu, 11 Jun 2020 07:06:59 +0200
Subject: [PATCH 2/6] queue/PlaylistEdit: fix crash in SetSongIdRange() while
 playing

An assertion failure in UpdateQueuedSong() could trigger because the
`prev` parameter is always `nullptr`, but `queued` may be set.  And in
fact, calling UpdateQueuedSong() is only necessary when the queued
song was edited, to re-queue it with the new range.

Closes https://github.com/MusicPlayerDaemon/MPD/issues/901
---
 NEWS                       | 2 ++
 src/queue/PlaylistEdit.cxx | 9 ++++++++-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/NEWS b/NEWS
index 2b5a446de..162346ec3 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,6 @@
 ver 0.21.25 (not yet released)
+* protocol:
+  - fix crash when using "rangeid" while playing
 
 ver 0.21.24 (2020/06/10)
 * protocol
diff --git a/src/queue/PlaylistEdit.cxx b/src/queue/PlaylistEdit.cxx
index 9a2b37eed..8655e0894 100644
--- a/src/queue/PlaylistEdit.cxx
+++ b/src/queue/PlaylistEdit.cxx
@@ -431,6 +431,8 @@ playlist::SetSongIdRange(PlayerControl &pc, unsigned id,
 	if (position < 0)
 		throw PlaylistError::NoSuchSong();
 
+	bool was_queued = false;
+
 	if (playing) {
 		if (position == current)
 			throw PlaylistError(PlaylistResult::DENIED,
@@ -442,6 +444,10 @@ playlist::SetSongIdRange(PlayerControl &pc, unsigned id,
 			   already; cancel that */
 			pc.LockCancel();
 			queued = -1;
+
+			/* schedule a call to UpdateQueuedSong() to
+			   re-queue the song with its new range */
+			was_queued = true;
 		}
 	}
 
@@ -464,7 +470,8 @@ playlist::SetSongIdRange(PlayerControl &pc, unsigned id,
 	song.SetEndTime(end);
 
 	/* announce the change to all interested subsystems */
-	UpdateQueuedSong(pc, nullptr);
+	if (was_queued)
+		UpdateQueuedSong(pc, nullptr);
 	queue.ModifyAtPosition(position);
 	OnModified();
 }

From 43c32372e7bd3e02edce0b4c2064a2a59e2b2166 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Mon, 22 Jun 2020 22:48:03 +0200
Subject: [PATCH 3/6] util/UriUtil: make `schemes` array static

---
 src/util/UriUtil.cxx | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/util/UriUtil.cxx b/src/util/UriUtil.cxx
index d8eee469c..c9100f4c0 100644
--- a/src/util/UriUtil.cxx
+++ b/src/util/UriUtil.cxx
@@ -167,7 +167,11 @@ gcc_pure
 static const char *
 SkipUriScheme(const char *uri) noexcept
 {
-	const char *const schemes[] = { "http://", "https://", "ftp://" };
+	static const char *const schemes[] = {
+		"http://", "https://",
+		"ftp://",
+	};
+
 	for (auto scheme : schemes) {
 		auto result = StringAfterPrefixCaseASCII(uri, scheme);
 		if (result != nullptr)

From a43ee977462fdd29d6fcc6084978f7a0c5666ff2 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Mon, 22 Jun 2020 22:48:49 +0200
Subject: [PATCH 4/6] util/UriUtil: strip credentials from smb:// URIs

Closes https://github.com/MusicPlayerDaemon/MPD/issues/910
---
 NEWS                 | 2 ++
 src/util/UriUtil.cxx | 1 +
 2 files changed, 3 insertions(+)

diff --git a/NEWS b/NEWS
index 162346ec3..bd4caf30b 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,8 @@
 ver 0.21.25 (not yet released)
 * protocol:
   - fix crash when using "rangeid" while playing
+* input
+  - smbclient: don't send credentials to MPD clients
 
 ver 0.21.24 (2020/06/10)
 * protocol
diff --git a/src/util/UriUtil.cxx b/src/util/UriUtil.cxx
index c9100f4c0..587a9a3a2 100644
--- a/src/util/UriUtil.cxx
+++ b/src/util/UriUtil.cxx
@@ -170,6 +170,7 @@ SkipUriScheme(const char *uri) noexcept
 	static const char *const schemes[] = {
 		"http://", "https://",
 		"ftp://",
+		"smb://",
 	};
 
 	for (auto scheme : schemes) {

From d9f9b3df1063b1a7c547484cec8dafc54da8c216 Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Wed, 1 Jul 2020 15:03:24 +0200
Subject: [PATCH 5/6] input/file: detect premature end of file

A bug report (https://github.com/MusicPlayerDaemon/MPD/issues/912)
suggests that on Linux, reading on `cifs` files may rarely return 0 (=
end of file) before the end of the file has really been reached.  But
that's just a theory which I need to validate, so this runtime check
shall catch this condition before the assertion in
DecoderBridge::Read() crashes MPD.  Let's see.

Closes https://github.com/MusicPlayerDaemon/MPD/issues/912
---
 NEWS                                  | 1 +
 src/input/plugins/FileInputPlugin.cxx | 7 +++++++
 2 files changed, 8 insertions(+)

diff --git a/NEWS b/NEWS
index bd4caf30b..c43b3b4f8 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,7 @@ ver 0.21.25 (not yet released)
 * protocol:
   - fix crash when using "rangeid" while playing
 * input
+  - file: detect premature end of file
   - smbclient: don't send credentials to MPD clients
 
 ver 0.21.24 (2020/06/10)
diff --git a/src/input/plugins/FileInputPlugin.cxx b/src/input/plugins/FileInputPlugin.cxx
index 989d3de74..0a6f31438 100644
--- a/src/input/plugins/FileInputPlugin.cxx
+++ b/src/input/plugins/FileInputPlugin.cxx
@@ -26,6 +26,8 @@
 #include "system/FileDescriptor.hxx"
 #include "util/RuntimeError.hxx"
 
+#include <cinttypes> // for PRIu64 (PRIoffset)
+
 #include <sys/stat.h>
 #include <fcntl.h>
 
@@ -94,6 +96,11 @@ FileInputStream::Read(void *ptr, size_t read_size)
 		nbytes = reader.Read(ptr, read_size);
 	}
 
+	if (nbytes == 0 && !IsEOF())
+		throw FormatRuntimeError("Unexpected end of file %s"
+					 " at %" PRIoffset " of %" PRIoffset,
+					 GetURI(), GetOffset(), GetSize());
+
 	offset += nbytes;
 	return nbytes;
 }

From ca705e1e37e2cd20d89e707c51cdb33a4d33245e Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Wed, 1 Jul 2020 16:37:50 +0200
Subject: [PATCH 6/6] python/build/meson.py: set BOOST_ROOT for Meson 0.54

Commit
https://github.com/mesonbuild/meson/commit/08224dafcba1b694fb624553e7d84deb565aae22
changed Meson to require BOOST_ROOT for cross builds.
---
 NEWS                  | 2 ++
 python/build/meson.py | 7 ++++++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/NEWS b/NEWS
index c43b3b4f8..99c52a92b 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,8 @@ ver 0.21.25 (not yet released)
 * input
   - file: detect premature end of file
   - smbclient: don't send credentials to MPD clients
+* Windows/Android:
+  - fix Boost detection after breaking change in Meson 0.54
 
 ver 0.21.24 (2020/06/10)
 * protocol
diff --git a/python/build/meson.py b/python/build/meson.py
index 93797f382..377969b28 100644
--- a/python/build/meson.py
+++ b/python/build/meson.py
@@ -91,7 +91,12 @@ def configure(toolchain, src, build, args=()):
         '--cross-file', cross_file,
     ] + args
 
-    subprocess.check_call(configure, env=toolchain.env)
+    env = toolchain.env.copy()
+
+    # Meson 0.54 requires the BOOST_ROOT environment variable
+    env['BOOST_ROOT'] = toolchain.install_prefix
+
+    subprocess.check_call(configure, env=env)
 
 class MesonProject(Project):
     def __init__(self, url, md5, installed, configure_args=[],