flate

deflate implementation
git clone git://git.suckless.org/flate
Log | Files | Refs | README

commit bc3229678243ab7844b5e6d8c9ac7ef348aed039
parent 76b3cac7919f6ea0663abb27e104a7c7a4235f56
Author: nsz <nszabolcs@gmail.com>
Date:   Fri, 21 Aug 2009 15:27:33 +0200

fix gzip checksum byte order
Diffstat:
sflate.c | 27+++++++++++++--------------
1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/sflate.c b/sflate.c @@ -3,10 +3,6 @@ #include <string.h> #include "flate.h" -static int checkfooter(uchar *p, uint sum) { - return sum == ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]); -} - enum { ZlibCM = 7 << 4, ZlibCINFO = 8, @@ -46,7 +42,8 @@ int inflate_zlib_header(uchar *p, int n) { } int inflate_zlib_footer(uchar *p, int n, uint sum, uint len, uint zlen) { - if (n < 4 || !checkfooter(p, sum)) + if (n < 4 || + sum != ((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3])) return FlateErr; return 4; } @@ -82,14 +79,14 @@ int deflate_gzip_header(uchar *p, int n) { int deflate_gzip_footer(uchar *p, int n, uint sum, uint len, uint zlen) { if (n < 8) return FlateErr; - p[0] = sum >> 24; - p[1] = sum >> 16; - p[2] = sum >> 8; - p[3] = sum; - p[4] = len >> 24; - p[5] = len >> 16; - p[6] = len >> 8; - p[7] = len; + p[0] = sum; + p[1] = sum >> 8; + p[2] = sum >> 16; + p[3] = sum >> 24; + p[4] = len; + p[5] = len >> 8; + p[6] = len >> 16; + p[7] = len >> 24; return 8; } @@ -130,7 +127,9 @@ int inflate_gzip_header(uchar *p, int n) { } int inflate_gzip_footer(uchar *p, int n, uint sum, uint len, uint zlen) { - if (n < 8 || !checkfooter(p, sum) || !checkfooter(p+4, len)) + if (n < 8 || + sum != (p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24)) || + len != (p[4] | (p[5] << 8) | (p[6] << 16) | (p[7] << 24))) return FlateErr; return 8; }