 |
|
| Science Forum Index » Compression Forum » zlib inflate woes...... |
|
Page 1 of 1 |
|
| Author |
Message |
| barcaroller... |
Posted: Thu Oct 22, 2009 5:09 pm |
|
|
|
Guest
|
I have two buffers that I pass to zlib's inflate function. I know for a
fact that both buffers contain valid zlib content because tools like
wireshark are able to inflate them. Using my code below, the first one
deflates successfully but the second one doesn't. Does anyone know why?
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. |
|
|
| Back to top |
|
|
|
| Mark Adler... |
Posted: Fri Oct 23, 2009 8:48 am |
|
|
|
Guest
|
On 2009-10-22 16:09:05 -0700, "barcaroller" <barcaroller at (no spam) music.net> said:
[quote]Using my code below, the first one deflates successfully but the second
one doesn't. Does anyone know why?
[/quote]
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 |
|
|
| Back to top |
|
|
|
| barcaroller... |
Posted: Fri Oct 23, 2009 3:54 pm |
|
|
|
Guest
|
"Mark Adler" <madler at (no spam) alumni.caltech.edu> wrote in message
news:2009102307485416807-madler at (no spam) alumnicaltechedu...
[quote]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.
[/quote]
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. |
|
|
| Back to top |
|
|
|
|
|
All times are GMT - 5 Hours
The time now is Wed Nov 25, 2009 2:44 am
|
|