Z_DATA_ERROR while decompressing header block

1185 views
Skip to first unread message

Ramon RiseRide Orrù

unread,
Mar 18, 2013, 12:18:39 PM3/18/13
to spdy...@googlegroups.com
I'm developing my own implementation of SPDY support for a web server written in C, when i decompress header blocks, i can decompress block from first frame without problems, calling inflate on second frame block returns a Z_DATA_ERROR (-3) code. I'm using this function:

int spdy_decompress_header_block( Byte* data, size_t data_len, unsigned char* processed, size_t* processed_len, z_stream* decomp) {

if (!decomp) {
    // I should return error...
    spdy_log_error("Error occurred getting decompressor!!!");
    return -1;
}

char decomp_buffer[HEADER_CHUNK_MAX_SIZE];
size_t decompressed_len = 0;
int rv = -1;

inflateReset(decomp);
decomp->next_in = data;
decomp->avail_in = data_len;
while (decomp->avail_in > 0) {

    decomp->next_out = (Byte*)decomp_buffer;
    decomp->avail_out = HEADER_CHUNK_MAX_SIZE;

    rv = inflate(decomp,Z_SYNC_FLUSH);

    if (rv == Z_NEED_DICT) {

        uLong dictionary_id = calculate_dictionary_id((Byte*)SPDY_dictionary, sizeof(SPDY_dictionary));

        if (decomp->adler == dictionary_id){

            rv = inflateSetDictionary(decomp, (Byte*)SPDY_dictionary, sizeof(SPDY_dictionary));
            rv = inflate(decomp, Z_SYNC_FLUSH);
        }

    }

    if ((rv == Z_OK) || ((rv == Z_BUF_ERROR) && (decomp->avail_in == 0))) {
        decompressed_len = HEADER_CHUNK_MAX_SIZE - decomp->avail_out;
        if (decompressed_len > 0) {
            memcpy(processed + *processed_len, decomp_buffer, decompressed_len);
            *processed_len += decompressed_len;
        }

    } else {
        if(rv == Z_DATA_ERROR){
            spdy_log_error("Error inflating headers:  Z_DATA_ERROR encountered" );
        }else{
            spdy_log_error("Error inflating headers!!!");
        }
        return -1;
    }

}
return *processed_len;

I can't figure how zlib header can't be present or correct , I'm using chrome 27.0.1438.7 dev for testing, and I'm sure bytes in the decomp input buffer are actually sent by chrome (wireshark checked).

Tatsuhiro Tsujikawa

unread,
Mar 18, 2013, 9:03:07 PM3/18/13
to spdy...@googlegroups.com


2013/03/19 1:18 "Ramon RiseRide Orrù" <gordonf...@gmail.com>:


>
> I'm developing my own implementation of SPDY support for a web server written in C, when i decompress header blocks, i can decompress block from first frame without problems, calling inflate on second frame block returns a Z_DATA_ERROR (-3) code. I'm using this function:
>

Spdy uses endless zlib stream per connection, not per stream. Try decompress incoming header block without re-initialize zlib context.

Best regards,

Tatsuhiro Tsujikawa

> --
>  
> ---
> You received this message because you are subscribed to the Google Groups "spdy-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to spdy-dev+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  

Ramon RiseRide Orrù

unread,
Mar 19, 2013, 6:55:25 AM3/19/13
to spdy...@googlegroups.com
Thanks for your reply, I'm using a context per connection, but I actually reset context before each block decompression, this would reset counters keeping context internal state, but I'm not sure it's a good idea, I will try your suggestion. 
thanks a lot! regards,
Ramon 

Roberto Peon

unread,
Mar 19, 2013, 2:45:07 PM3/19/13
to spdy...@googlegroups.com
Tatsuhiro Tsujikawa is absolutely correct-- the compression context should not be reset, and is done per connection.


-=R

Ramon RiseRide Orrù

unread,
Apr 5, 2013, 7:43:26 AM4/5/13
to spdy...@googlegroups.com
Thank you guys, I tried eliminating inflateReset and everything goes right.
Thak you very much.
Ramon

Vimala Tadepalli

unread,
Mar 27, 2015, 8:00:35 PM3/27/15
to spdy...@googlegroups.com
Hi tatsuhiro,

Is it the same for HTTP 2.0 HPACK encoding and decoding?
is it done continuously?

Thanks
Vimala
Reply all
Reply to author
Forward
0 new messages