Author: dcreager Date: Thu Sep 13 21:20:34 2012 New Revision: 1384540 URL: http://svn.apache.org/viewvc?rev=1384540&view=rev Log: AVRO-1158. C: Fix infinite loop in delate codec decompression. Contributed by Lucas Martin-King. Modified: avro/trunk/CHANGES.txt avro/trunk/lang/c/src/codec.c avro/trunk/lang/c/src/datafile.c Modified: avro/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1384540&r1=1384539&r2=1384540&view=diff ============================================================================== --- avro/trunk/CHANGES.txt (original) +++ avro/trunk/CHANGES.txt Thu Sep 13 21:20:34 2012 @@ -61,6 +61,9 @@ Avro 1.7.2 (unreleased) AVRO-1154. Java: Fix NettyTransciever to not hang when the server is stopped. (Karel Vervaeke & Bruno Dumon via cutting) + AVRO-1158. C: Fixed infinite loop in deflate decompression codec. + (Lucas Martin-King via dcreager) + Avro 1.7.1 (16 July 2012) NEW FEATURES Modified: avro/trunk/lang/c/src/codec.c URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/src/codec.c?rev=1384540&r1=1384539&r2=1384540&view=diff ============================================================================== --- avro/trunk/lang/c/src/codec.c (original) +++ avro/trunk/lang/c/src/codec.c Thu Sep 13 21:20:34 2012 @@ -207,6 +207,14 @@ static int decode_deflate(avro_codec_t c { err = inflate(s, Z_FINISH); + // Apparently if there is yet available space in the output then something + // has gone wrong in decompressing the data (according to cpython zlibmodule.c) + if (err == Z_BUF_ERROR && s->avail_out > 0) { + inflateEnd(s); + avro_set_error("Error decompressing block with deflate, possible data error"); + return 1; + } + // The buffer was not big enough. resize it. if (err == Z_BUF_ERROR) { @@ -229,6 +237,7 @@ static int decode_deflate(avro_codec_t c c->used_size = s->total_out; if (inflateReset(s) != Z_OK) { + avro_set_error("Error resetting deflate decompression"); return 1; } Modified: avro/trunk/lang/c/src/datafile.c URL: http://svn.apache.org/viewvc/avro/trunk/lang/c/src/datafile.c?rev=1384540&r1=1384539&r2=1384540&view=diff ============================================================================== --- avro/trunk/lang/c/src/datafile.c (original) +++ avro/trunk/lang/c/src/datafile.c Thu Sep 13 21:20:34 2012 @@ -453,7 +453,8 @@ static int file_read_block_count(avro_fi check_prefix(rval, avro_read(r->reader, r->current_blockdata, len), "Cannot read file block: "); - avro_codec_decode(r->codec, r->current_blockdata, len); + check_prefix(rval, avro_codec_decode(r->codec, r->current_blockdata, len), + "Cannot decode file block: "); avro_reader_memory_set_source(r->block_reader, (const char *) r->codec->block_data, r->codec->used_size);