Commit d9f9b3df authored by Max Kellermann's avatar Max Kellermann

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
parent a43ee977
......@@ -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)
......
......@@ -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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment