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:
Max Kellermann 2020-07-01 15:03:24 +02:00
parent a43ee97746
commit d9f9b3df10
2 changed files with 8 additions and 0 deletions

1
NEWS
View File

@ -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)

View File

@ -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;
}