Skip to content

Commit

Permalink
lib: Fixed istream_seekable.stat() to return correct size.
Browse files Browse the repository at this point in the history
It was supposed to read until end of the stream, but it did it only when
stat() was called while stream was still fully in memory.
  • Loading branch information
sirainen committed May 13, 2016
1 parent ed47ce7 commit 31fc5ca
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions src/lib/istream-seekable.c
Expand Up @@ -316,25 +316,24 @@ i_stream_seekable_stat(struct istream_private *stream, bool exact)
return 0;
}

if (sstream->membuf != NULL) {
/* we want to know the full size of the file, so read until
we're finished */
old_offset = stream->istream.v_offset;
do {
i_stream_skip(&stream->istream,
stream->pos - stream->skip);
} while ((ret = i_stream_seekable_read(stream)) > 0);

if (ret == 0) {
i_panic("i_stream_stat() used for non-blocking "
"seekable stream %s offset %"PRIuUOFF_T,
i_stream_get_name(sstream->cur_input),
sstream->cur_input->v_offset);
}
i_stream_skip(&stream->istream, stream->pos - stream->skip);
i_stream_seek(&stream->istream, old_offset);
unref_streams(sstream);
/* we want to know the full size of the file, so read until
we're finished */
old_offset = stream->istream.v_offset;
do {
i_stream_skip(&stream->istream,
stream->pos - stream->skip);
} while ((ret = i_stream_seekable_read(stream)) > 0);

if (ret == 0) {
i_panic("i_stream_stat() used for non-blocking "
"seekable stream %s offset %"PRIuUOFF_T,
i_stream_get_name(sstream->cur_input),
sstream->cur_input->v_offset);
}
i_stream_skip(&stream->istream, stream->pos - stream->skip);
i_stream_seek(&stream->istream, old_offset);
unref_streams(sstream);

if (stream->istream.stream_errno != 0)
return -1;

Expand Down

0 comments on commit 31fc5ca

Please sign in to comment.