[hackers] [flate] fix gzip checksum byte order || nsz

From: <hg_AT_suckless.org>
Date: Fri, 21 Aug 2009 13:50:15 +0000 (UTC)

changeset: 111:f534b13f0b68
user: nsz <nszabolcs_AT_gmail.com>
date: Fri Aug 21 15:27:33 2009 +0200
files: sflate.c
description:
fix gzip checksum byte order

diff -r 044cf880002d -r f534b13f0b68 sflate.c
--- a/sflate.c Fri Aug 21 15:03:20 2009 +0200
+++ b/sflate.c Fri Aug 21 15:27:33 2009 +0200
@@ -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_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_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_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;
 }
Received on Fri Aug 21 2009 - 13:50:15 UTC

This archive was generated by hypermail 2.2.0 : Fri Aug 21 2009 - 14:00:14 UTC