From d9f9b3df1063b1a7c547484cec8dafc54da8c216 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 1 Jul 2020 15:03:24 +0200 Subject: [PATCH] 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 // for PRIu64 (PRIoffset) + #include #include @@ -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; }