X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/halibut/blobdiff_plain/a7fd1ff1031dea536cb68cec2e52779b7ffe4fc1..a80c47a8f5806b2163f99fadc374897519499670:/deflate.c diff --git a/deflate.c b/deflate.c index 685097b..d614c37 100644 --- a/deflate.c +++ b/deflate.c @@ -95,7 +95,7 @@ #define debug_int(x...) ( fprintf(stderr, x) ) #define debug(x) ( debug_int x ) #else -#define debug(x) +#define debug(x) ((void)0) #endif #ifdef STANDALONE @@ -651,8 +651,8 @@ struct deflate_compress_ctx { unsigned long datasize; int lastblock; int finished; - unsigned char static_len1[286], static_len2[30]; - int static_code1[286], static_code2[30]; + unsigned char static_len1[288], static_len2[30]; + int static_code1[288], static_code2[30]; struct huftrees sht; #ifdef STATISTICS unsigned long bitcount; @@ -1576,11 +1576,11 @@ deflate_compress_ctx *deflate_compress_new(int type) { int i; - for (i = 0; i < lenof(out->static_len1); i++) + for (i = 0; i < (int)lenof(out->static_len1); i++) out->static_len1[i] = (i < 144 ? 8 : i < 256 ? 9 : i < 280 ? 7 : 8); - for (i = 0; i < lenof(out->static_len2); i++) + for (i = 0; i < (int)lenof(out->static_len2); i++) out->static_len2[i] = 5; } hufcodes(out->static_len1, out->static_code1, lenof(out->static_code1)); @@ -2041,7 +2041,8 @@ int deflate_decompress_data(deflate_decompress_ctx *dctx, { const coderecord *rec; const unsigned char *block = (const unsigned char *)vblock; - int code, bfinal, btype, rep, dist, nlen, header, cksum; + int code, bfinal, btype, rep, dist, nlen, header; + unsigned long cksum; int error = 0; if (len == 0) { @@ -2442,9 +2443,16 @@ int deflate_decompress_data(deflate_decompress_ctx *dctx, goto finished; nlen = dctx->bits & 0xFFFF; EATBITS(16); - if (dctx->uncomplen == 0) - dctx->state = OUTSIDEBLK; /* block is empty */ - else + if (dctx->uncomplen != (nlen ^ 0xFFFF)) { + error = DEFLATE_ERR_UNCOMP_HDR; + goto finished; + } + if (dctx->uncomplen == 0) {/* block is empty */ + if (dctx->lastblock) + dctx->state = END; + else + dctx->state = OUTSIDEBLK; + } else dctx->state = UNCOMP_DATA; break; case UNCOMP_DATA: @@ -2457,8 +2465,12 @@ int deflate_decompress_data(deflate_decompress_ctx *dctx, #endif emit_char(dctx, dctx->bits & 0xFF); EATBITS(8); - if (--dctx->uncomplen == 0) - dctx->state = OUTSIDEBLK; /* end of uncompressed block */ + if (--dctx->uncomplen == 0) { /* end of uncompressed block */ + if (dctx->lastblock) + dctx->state = END; + else + dctx->state = OUTSIDEBLK; + } break; case END: /*