From 05db6934eb12e859b99f34c4d96674aeaa1ff90a Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Mon, 21 Jan 2019 22:16:46 +0100
Subject: [PATCH] FileCommands: fix deadlock in "albumart" command

Must lock the mutex before calling any of the unprotected InputStream methods.

Closes #462
---
 NEWS                         | 2 ++
 src/command/FileCommands.cxx | 7 +++++--
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/NEWS b/NEWS
index b6dc41c13..5996aecbf 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,6 @@
 ver 0.21.5 (not yet released)
+* protocol
+  - fix deadlock in "albumart" command
 * tags
   - ape: map "Album Artist"
 * output
diff --git a/src/command/FileCommands.cxx b/src/command/FileCommands.cxx
index 863c7170e..c8af5c19b 100644
--- a/src/command/FileCommands.cxx
+++ b/src/command/FileCommands.cxx
@@ -285,8 +285,11 @@ read_stream_art(Response &r, const char *uri, size_t offset)
 	uint8_t buffer[CHUNK_SIZE];
 	size_t read_size;
 
-	is->Seek(offset);
-	read_size = is->Read(&buffer, CHUNK_SIZE);
+	{
+		const std::lock_guard<Mutex> protect(mutex);
+		is->Seek(offset);
+		read_size = is->Read(&buffer, CHUNK_SIZE);
+	}
 
 	r.Format("size: %" PRIoffset "\n"
 			 "binary: %u\n",