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
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user