Skip to content

Commit

Permalink
fs-metawrap: Fixed buffer size while reading metadata header.
Browse files Browse the repository at this point in the history
It's not enough to have the buffer size set to "large enough" at the time of
the stream creation, because i_stream_set_max_buffer_size() could be called
afterwards.
  • Loading branch information
sirainen committed Jun 1, 2016
1 parent dc43757 commit 9e7b4d6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/lib-fs/fs-metawrap.c
Expand Up @@ -13,8 +13,6 @@
#include "iostream-temp.h"
#include "fs-api-private.h"

#define MAX_METADATA_LINE_LEN 8192

struct metawrap_fs {
struct fs fs;
bool wrap_metadata;
Expand Down Expand Up @@ -283,8 +281,7 @@ fs_metawrap_read_stream(struct fs_file *_file, size_t max_buffer_size)
return file->input;
}

input = fs_read_stream(file->super_read,
I_MAX(max_buffer_size, MAX_METADATA_LINE_LEN));
input = fs_read_stream(file->super_read, max_buffer_size);
file->input = i_stream_create_metawrap(input, fs_metawrap_callback, file);
i_stream_unref(&input);
i_stream_ref(file->input);
Expand Down
7 changes: 7 additions & 0 deletions src/lib-fs/istream-metawrap.c
Expand Up @@ -4,6 +4,8 @@
#include "istream-private.h"
#include "istream-metawrap.h"

#define METAWRAP_MAX_METADATA_LINE_LEN 8192

struct metawrap_istream {
struct istream_private istream;
metawrap_callback_t *callback;
Expand Down Expand Up @@ -60,7 +62,12 @@ static ssize_t i_stream_metawrap_read(struct istream_private *stream)
stream->istream.v_offset);

if (mstream->in_metadata) {
size_t prev_max_size = i_stream_get_max_buffer_size(stream->parent);

i_stream_set_max_buffer_size(stream->parent, METAWRAP_MAX_METADATA_LINE_LEN);
ret = metadata_header_read(mstream);
i_stream_set_max_buffer_size(stream->parent, prev_max_size);

i_assert(stream->istream.v_offset == 0);
mstream->start_offset = stream->parent->v_offset;
if (ret <= 0)
Expand Down

0 comments on commit 9e7b4d6

Please sign in to comment.