From ffc36d525535d101c8c2cf5d382899bd7e86853f Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Tue, 22 Jan 2019 07:42:00 +0100
Subject: [PATCH] input/buffered: implement seeking to end of file

Previously, a seek to the end of the file would cause an assertion
failure in SparseMap::Check() because the given offset was invalid.

Closes #453
---
 NEWS                              | 2 ++
 src/input/BufferedInputStream.cxx | 5 +++++
 2 files changed, 7 insertions(+)

diff --git a/NEWS b/NEWS
index 5996aecbf..ef435d9f7 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,8 @@
 ver 0.21.5 (not yet released)
 * protocol
   - fix deadlock in "albumart" command
+* input
+  - buffer: fix crash bug when playing remote WAV file
 * tags
   - ape: map "Album Artist"
 * output
diff --git a/src/input/BufferedInputStream.cxx b/src/input/BufferedInputStream.cxx
index 98cd5293c..a5688de47 100644
--- a/src/input/BufferedInputStream.cxx
+++ b/src/input/BufferedInputStream.cxx
@@ -66,6 +66,11 @@ BufferedInputStream::Check()
 void
 BufferedInputStream::Seek(offset_type new_offset)
 {
+	if (new_offset >= size) {
+		offset = size;
+		return;
+	}
+
 	auto r = buffer.Read(new_offset);
 	if (r.HasData()) {
 		/* nice, we already have some data at the desired