Reputation: 11
I am trying to use MINIZ library in my embedded device, and am almost done with success except for an issue in decompressing, similar to the one reported here: Wrap buffer in minizs tinfl_decompress
Basically, my code will only work fine as long as the size of decompressed data is smaller than the given output buffer, otherwise I get corrupted bytes: I know I should handle TINFL_STATUS_HAS_MORE_OUTPUT return code, but even after trying several ways, and searching for examples, that behaviour never changes.
This is my code:
int i=0;
tinfl_decompressor decomp;
tinfl_status status;
uint8_t ibuf[256],obuf[TINFL_LZ_DICT_SIZE];
size_t src_buf_len,out_buf_len;
int out_buf_ofs;
*crc=0xffffffff;
*len=0;
tinfl_init(&decomp);
out_buf_ofs=0;
src_buf_len=sizeof(ibuf);
do {
src_buf_len=SuperFileRead(f1,ibuf,min(totbytes,sizeof(ibuf)));
out_buf_len=TINFL_LZ_DICT_SIZE-out_buf_ofs;
status = tinfl_decompress(&decomp,ibuf,&src_buf_len,
obuf, ((uint8_t*)obuf)+out_buf_ofs, &out_buf_len,
/*flags |*/ (totbytes>0 ? TINFL_FLAG_HAS_MORE_INPUT : 0));
totbytes-=src_buf_len;
if(status != TINFL_STATUS_DONE)
SuperFileSeek(f1,src_buf_len-sizeof(ibuf),SEEK_CUR); // occhio alla fine...
//ovvero SuperFileSeek(f1, ,SEEK_SET);
if(out_buf_len) {
if(SuperFileWrite(f2,((uint8_t*)obuf)+out_buf_ofs,out_buf_len) != out_buf_len)
break;
*len+=out_buf_len;
}
*crc=crc32array(((uint8_t*)obuf)+out_buf_ofs,out_buf_len,*crc);
out_buf_ofs = (out_buf_ofs+out_buf_len) & (TINFL_LZ_DICT_SIZE-1);
if(!totbytes) // safety cmq
break;
} while(status==TINFL_STATUS_NEEDS_MORE_INPUT || status == TINFL_STATUS_HAS_MORE_OUTPUT);
*crc=~Reflect32(*crc);
(tried different output size and still get the same)
I've been reading and studying example code, and trying different buffer sizes (and small changes in pointer management, and configuration parameters/constants), but the above error is consistent and never changes
The post I am referring to says "the issue was solved" but does not show exactly how.
Is there some mistake I am still running into? thanks
Upvotes: 1
Views: 17