This is the mail archive of the ecos-patches@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

gzip crc calulation fix


Recent changes to the way load streams are handled (I think) exposed a
problem with CRC calculation of gzip'ed files.

--Mark

Index: services/compress/zlib/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/services/compress/zlib/current/ChangeLog,v
retrieving revision 1.5
diff -u -p -5 -r1.5 ChangeLog
--- services/compress/zlib/current/ChangeLog	23 May 2002 23:08:36 -0000	1.5
+++ services/compress/zlib/current/ChangeLog	9 Sep 2002 17:15:48 -0000
@@ -1,5 +1,10 @@
+2002-09-09  Mark Salter  <msalter@redhat.com>
+
+	* inflate.c (inflate): Fix CRC calculation over multiple invocations
+	with same output buffer. 
+	
 2002-02-18  Jesper Skov  <jskov@redhat.com>
 
 	* src/infblock.c: Applied fix for double-free which could cause a
 	zlib crash. Fixed indentation.
 
Index: services/compress/zlib/current/src/inflate.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/services/compress/zlib/current/src/inflate.c,v
retrieving revision 1.1
diff -u -p -5 -r1.1 inflate.c
--- services/compress/zlib/current/src/inflate.c	6 Apr 2001 17:20:42 -0000	1.1
+++ services/compress/zlib/current/src/inflate.c	9 Sep 2002 17:15:48 -0000
@@ -47,10 +47,11 @@ struct internal_state {
 #ifdef __ECOS__
     inflate_mode gz_mode;
     uInt gz_flag;
     int gz_cnt;
     unsigned char* gz_start;
+    uLong gz_sum;
 #endif
 
   /* mode dependent information */
   union {
     uInt method;        /* if FLAGS, method byte */
@@ -323,10 +324,11 @@ int f;
   case GZ_DONE:
       // Remember where output is written to and flag that this is a
       // gz stream by setting the gz_mode.
       z->state->gz_start = z->next_out;
       z->state->gz_mode = BLOCKS;
+      z->state->gz_sum = 0;
 
       // Depending on the flag select correct next step
       // (clone of code in FLAG)
       if (!(z->state->gz_flag & PRESET_DICT))
           z->state->mode = BLOCKS;
@@ -373,19 +375,29 @@ int f;
       z->state->mode = BAD;
       z->msg = (char*)"need dictionary";
       z->state->sub.marker = 0;       /* can try inflateSync */
       return Z_STREAM_ERROR;
     case BLOCKS:
+#ifdef __ECOS__
+      if (z->state->gz_mode != DONE)
+        z->state->gz_start = z->next_out;
+#endif
       r = inflate_blocks(z->state->blocks, z, r);
       if (r == Z_DATA_ERROR)
       {
         z->state->mode = BAD;
         z->state->sub.marker = 0;       /* can try inflateSync */
         break;
       }
       if (r == Z_OK)
         r = f;
+#ifdef __ECOS__
+      if (z->state->gz_mode != DONE)
+        z->state->gz_sum = gz_crc32(z->state->gz_sum,
+				    z->state->gz_start,
+				    z->next_out - z->state->gz_start);
+#endif
       if (r != Z_STREAM_END)
         return r;
       r = f;
       inflate_blocks_reset(z->state->blocks, z, &z->state->sub.check.was);
       if (z->state->nowrap)
@@ -412,11 +424,11 @@ int f;
 
 #ifdef __ECOS__
       if (z->state->gz_mode != DONE) {
           // Byte swap CRC since it is read in the opposite order as
           // written by gzip.
-          unsigned long c = gz_crc32(0, z->state->gz_start, z->next_out - z->state->gz_start);
+          unsigned long c = z->state->gz_sum;
           z->state->sub.check.was = (((c & 0xff000000) >> 24) | ((c & 0x00ff0000) >> 8)
                                      | ((c & 0x0000ff00) << 8) | ((c & 0x000000ff) << 24));
           
       }
 #endif


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]