Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream: don't try to read from all-sparse/no-data files #13817

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,9 @@ endif
features += {'ppoll': cc.has_function('ppoll', args: '-D_GNU_SOURCE',
prefix: '#include <poll.h>')}

features += {'seek-data': cc.has_header_symbol('errno.h', 'ENXIO') and
cc.has_header_symbol('unistd.h', 'SEEK_DATA', args: '-D_GNU_SOURCE')}

cd_devices = {
'windows': 'D:',
'cygwin': 'D:',
Expand Down
11 changes: 11 additions & 0 deletions stream/stream_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,17 @@ static int open_f(stream_t *stream, const struct stream_open_args *args)
setmode(p->fd, O_BINARY);
#endif

#if HAVE_SEEK_DATA
if (stream->mode == STREAM_READ) {
off_t first_data = lseek(p->fd, 0, SEEK_DATA);
if (first_data == (off_t)-1 && errno == ENXIO) {
MP_ERR(stream, "File is empty or all sparse (has no data).\n");
s_close(stream);
return STREAM_ERROR;
kasper93 marked this conversation as resolved.
Show resolved Hide resolved
}
}
#endif
MoSal marked this conversation as resolved.
Show resolved Hide resolved

off_t len = lseek(p->fd, 0, SEEK_END);
lseek(p->fd, 0, SEEK_SET);
if (len != (off_t)-1) {
Expand Down