istream-lz4.c (dovecot-2.3.16) | : | istream-lz4.c (dovecot-2.3.17) | ||
---|---|---|---|---|
skipping to change at line 50 | skipping to change at line 50 | |||
i_stream_get_absolute_offset(&zstream->istream.istrea m)); | i_stream_get_absolute_offset(&zstream->istream.istrea m)); | |||
} | } | |||
static int i_stream_lz4_read_header(struct lz4_istream *zstream) | static int i_stream_lz4_read_header(struct lz4_istream *zstream) | |||
{ | { | |||
const struct iostream_lz4_header *hdr; | const struct iostream_lz4_header *hdr; | |||
const unsigned char *data; | const unsigned char *data; | |||
size_t size; | size_t size; | |||
int ret; | int ret; | |||
ret = i_stream_read_more(zstream->istream.parent, &data, &size); | ret = i_stream_read_bytes(zstream->istream.parent, &data, | |||
&size, sizeof(*hdr)); | ||||
size = I_MIN(size, sizeof(*hdr)); | size = I_MIN(size, sizeof(*hdr)); | |||
buffer_append(zstream->chunk_buf, data, size); | buffer_append(zstream->chunk_buf, data, size); | |||
i_stream_skip(zstream->istream.parent, size); | i_stream_skip(zstream->istream.parent, size); | |||
if (ret < 0) { | if (ret < 0 || (ret == 0 && zstream->istream.istream.eof)) { | |||
i_assert(ret != -2); | ||||
if (zstream->istream.istream.stream_errno == 0) { | if (zstream->istream.istream.stream_errno == 0) { | |||
lz4_read_error(zstream, "missing header (not lz4 file?)") ; | lz4_read_error(zstream, "missing header (not lz4 file?)") ; | |||
zstream->istream.istream.stream_errno = EINVAL; | zstream->istream.istream.stream_errno = EINVAL; | |||
} else | } else | |||
zstream->istream.istream.stream_errno = | zstream->istream.istream.stream_errno = | |||
zstream->istream.parent->stream_errno; | zstream->istream.parent->stream_errno; | |||
return ret; | return ret; | |||
} | } | |||
if (ret == 0 && !zstream->istream.istream.eof) | if (zstream->chunk_buf->used < sizeof(*hdr)) { | |||
return 0; | i_assert(!zstream->istream.istream.blocking); | |||
if (zstream->chunk_buf->used < sizeof(*hdr)) | ||||
return 0; | return 0; | |||
} | ||||
hdr = zstream->chunk_buf->data; | hdr = zstream->chunk_buf->data; | |||
if (ret == 0 || memcmp(hdr->magic, IOSTREAM_LZ4_MAGIC, | if (ret == 0 || memcmp(hdr->magic, IOSTREAM_LZ4_MAGIC, | |||
IOSTREAM_LZ4_MAGIC_LEN) != 0) { | IOSTREAM_LZ4_MAGIC_LEN) != 0) { | |||
lz4_read_error(zstream, "wrong magic in header (not lz4 file?)"); | lz4_read_error(zstream, "wrong magic in header (not lz4 file?)"); | |||
zstream->istream.istream.stream_errno = EINVAL; | zstream->istream.istream.stream_errno = EINVAL; | |||
return -1; | return -1; | |||
} | } | |||
zstream->max_uncompressed_chunk_size = | zstream->max_uncompressed_chunk_size = | |||
be32_to_cpu_unaligned(hdr->max_uncompressed_chunk_size); | be32_to_cpu_unaligned(hdr->max_uncompressed_chunk_size); | |||
skipping to change at line 102 | skipping to change at line 104 | |||
size_t size; | size_t size; | |||
const unsigned char *data; | const unsigned char *data; | |||
struct istream_private *stream = &zstream->istream; | struct istream_private *stream = &zstream->istream; | |||
i_assert(zstream->chunk_buf->used <= IOSTREAM_LZ4_CHUNK_PREFIX_LEN); | i_assert(zstream->chunk_buf->used <= IOSTREAM_LZ4_CHUNK_PREFIX_LEN); | |||
ret = i_stream_read_more(stream->parent, &data, &size); | ret = i_stream_read_more(stream->parent, &data, &size); | |||
size = I_MIN(size, IOSTREAM_LZ4_CHUNK_PREFIX_LEN - zstream->chunk_buf->us ed); | size = I_MIN(size, IOSTREAM_LZ4_CHUNK_PREFIX_LEN - zstream->chunk_buf->us ed); | |||
buffer_append(zstream->chunk_buf, data, size); | buffer_append(zstream->chunk_buf, data, size); | |||
i_stream_skip(stream->parent, size); | i_stream_skip(stream->parent, size); | |||
if (ret < 0) { | if (ret < 0) { | |||
i_assert(ret != -2); | ||||
stream->istream.stream_errno = stream->parent->stream_errno; | stream->istream.stream_errno = stream->parent->stream_errno; | |||
if (stream->istream.stream_errno == 0) { | if (stream->istream.stream_errno == 0) { | |||
stream->istream.eof = TRUE; | stream->istream.eof = TRUE; | |||
stream->cached_stream_size = | stream->cached_stream_size = | |||
stream->istream.v_offset + | stream->istream.v_offset + | |||
stream->pos - stream->skip; | stream->pos - stream->skip; | |||
} | } | |||
return ret; | return ret; | |||
} | } | |||
i_assert(ret != 0 || !stream->istream.blocking); | i_assert(ret != 0 || !stream->istream.blocking); | |||
skipping to change at line 150 | skipping to change at line 153 | |||
if (!zstream->header_read) { | if (!zstream->header_read) { | |||
if ((ret = i_stream_lz4_read_header(zstream)) <= 0) { | if ((ret = i_stream_lz4_read_header(zstream)) <= 0) { | |||
stream->istream.eof = TRUE; | stream->istream.eof = TRUE; | |||
return ret; | return ret; | |||
} | } | |||
zstream->header_read = TRUE; | zstream->header_read = TRUE; | |||
} | } | |||
if (zstream->chunk_left == 0) { | if (zstream->chunk_left == 0) { | |||
while ((ret = i_stream_lz4_read_chunk_header(zstream)) == 0) { | while ((ret = i_stream_lz4_read_chunk_header(zstream)) == 0) { | |||
if (ret == 0 && !stream->istream.blocking) | if (!stream->istream.blocking) | |||
return 0; | return 0; | |||
} | } | |||
if (ret < 0) | if (ret < 0) | |||
return ret; | return ret; | |||
} | } | |||
/* read the whole compressed chunk into memory */ | /* read the whole compressed chunk into memory */ | |||
while (zstream->chunk_left > 0 && | while (zstream->chunk_left > 0 && | |||
(ret = i_stream_read_more(zstream->istream.parent, &data, &size)) > 0) { | (ret = i_stream_read_more(zstream->istream.parent, &data, &size)) > 0) { | |||
if (size > zstream->chunk_left) | if (size > zstream->chunk_left) | |||
End of changes. 6 change blocks. | ||||
6 lines changed or deleted | 9 lines changed or added |