First Buffer:
uchar in[] = { 0x78,0x9c,0x12,0x61,
0x60,0xe0,0xb9,0xf2,
0x9b,0x25,0xbd,0x75,
0xc2,0xcb,0xcf,0x79,
0x49,0xa7,0x32,0x01,
0x00,0x00,0x00,0xff,
0xff };
Deflates successfully (to 14 00 00 0c d4 fb 04 67 85 90 e9 f3 6e 62 ca 69)
even though the 3-bit zlib header is 011 (reserved/error).
Second Buffer:
uchar in[] = { 0x4a,0x49,0x2b,0x4e,
0x4f,0x49,0x03,0xa1,
0x62,0x08,0x05,0x44,
0x69,0xe9,0x5c,0x00,
0x00,0x00,0x00,0xff,
0xff };
Causes a zlib error ("incorrect header check") even though the 3-bit zlib
header is 010 (compressed with dynamic Huffman codes).
The code I used is:
z_stream istream_;
istream_.zalloc = Z_NULL;
istream_.zfree = Z_NULL;
istream_.opaque = Z_NULL;
istream_.next_in = Z_NULL;
istream_.next_out = Z_NULL;
istream_.avail_in = 0;
istream_.avail_out = 0;
int zReturn_ = inflateInit(&istream_);
if (zReturn_ != Z_OK)
{
// Error
}
uchar in[] = {
// see buffers above
};
uchar out[16000];
istream_.next_in = in;
istream_.avail_in = sizeof(in);
istream_.next_out = out;
istream_.avail_out = sizeof(out);
zReturn_ = inflate(&istream_, Z_SYNC_FLUSH);
if (zReturn_ != Z_OK)
{
// Error
}
I also tried inflate() with Z_FINISH. I then tried zlib's uncompress().
Nothing worked.
These are fragments of a zlib compressed stream. �The first one is from
the beginning of a zlib stream, the second is from the middle. �You can
use raw inflate for the second one -- look at inflateInit2().
It looks like the source of the data is using Z_FULL_FLUSH to break the
stream into pieces at byte boundaries and sending the pieces.
Mark
> These are fragments of a zlib compressed stream. The first one is from the
> beginning of a zlib stream, the second is from the middle. You can use raw
> inflate for the second one -- look at inflateInit2().
>
> It looks like the source of the data is using Z_FULL_FLUSH to break the
> stream into pieces at byte boundaries and sending the pieces.
Thank you. You gave me a valuable hint. SSL/TLS breaks a stream into SSL
records and compresses each record individually. I was decompressing each
record individually, not realizing that the order was important (I was
deliberately skipping some of the records). zlib's inflate(Z_SYNC_FLUSH) now
works as expected. Thanks again for your time.