Commit 09e67de3 authored by Damien George's avatar Damien George

stm32/mboot/gzstream: Fix lost data decompressing final part of file.

Prior to this fix, the final piece of data in a compressed file may have
been lost when decompressing.
Signed-off-by: default avatarDamien George <damien@micropython.org>
parent 0ce69486
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
typedef struct _gz_stream_t { typedef struct _gz_stream_t {
void *stream_data; void *stream_data;
stream_read_t stream_read; stream_read_t stream_read;
TINF_DATA tinf; struct uzlib_uncomp tinf;
uint8_t buf[512]; uint8_t buf[512];
uint8_t dict[DICT_SIZE]; uint8_t dict[DICT_SIZE];
} gz_stream_t; } gz_stream_t;
...@@ -66,7 +66,7 @@ int gz_stream_init(void *stream_data, stream_read_t stream_read) { ...@@ -66,7 +66,7 @@ int gz_stream_init(void *stream_data, stream_read_t stream_read) {
gz_stream.stream_read = stream_read; gz_stream.stream_read = stream_read;
memset(&gz_stream.tinf, 0, sizeof(gz_stream.tinf)); memset(&gz_stream.tinf, 0, sizeof(gz_stream.tinf));
gz_stream.tinf.readSource = gz_stream_read_src; gz_stream.tinf.source_read_cb = gz_stream_read_src;
int st = uzlib_gzip_parse_header(&gz_stream.tinf); int st = uzlib_gzip_parse_header(&gz_stream.tinf);
if (st != TINF_OK) { if (st != TINF_OK) {
...@@ -79,15 +79,21 @@ int gz_stream_init(void *stream_data, stream_read_t stream_read) { ...@@ -79,15 +79,21 @@ int gz_stream_init(void *stream_data, stream_read_t stream_read) {
} }
int gz_stream_read(size_t len, uint8_t *buf) { int gz_stream_read(size_t len, uint8_t *buf) {
if (gz_stream.tinf.source == NULL && gz_stream.tinf.source_read_cb == NULL) {
// End of stream.
return 0;
}
gz_stream.tinf.dest = buf; gz_stream.tinf.dest = buf;
gz_stream.tinf.dest_limit = buf + len; gz_stream.tinf.dest_limit = buf + len;
int st = uzlib_uncompress_chksum(&gz_stream.tinf); int st = uzlib_uncompress_chksum(&gz_stream.tinf);
if (st == TINF_DONE) {
return 0;
}
if (st < 0) { if (st < 0) {
return st; return st;
} }
if (st == TINF_DONE) {
// Indicate end-of-stream for subsequent calls.
gz_stream.tinf.source = NULL;
gz_stream.tinf.source_read_cb = NULL;
}
return gz_stream.tinf.dest - buf; return gz_stream.tinf.dest - buf;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment