Code

Fixed end-of-block marker
authorishmal <ishmal@users.sourceforge.net>
Fri, 14 Apr 2006 08:20:06 +0000 (08:20 +0000)
committerishmal <ishmal@users.sourceforge.net>
Fri, 14 Apr 2006 08:20:06 +0000 (08:20 +0000)
src/dom/util/ziptool.cpp
src/dom/util/ziptool.h

index 72b7e63b7e1c57783e01c5f4127c6102c38a23a7..701b9d9eba17c77aef449c79b59312065dcbdd95 100644 (file)
@@ -867,6 +867,8 @@ private:
 \r
     //#### Huffman Encode\r
     void encodeLiteralStatic(unsigned int ch);\r
+\r
+    unsigned char windowBuf[32768];\r
 };\r
 \r
 \r
@@ -1264,6 +1266,11 @@ void Deflater::encodeDistStatic(unsigned int len, unsigned int dist)
 bool Deflater::compressWindow()\r
 {\r
     //### Compress as much of the window as possible\r
+    int i=0;\r
+    std::vector<unsigned char>::iterator iter;\r
+    for (iter=window.begin() ; iter!=window.end() ; iter++)\r
+        windowBuf[i++] = *iter;\r
+\r
     while (windowPos < window.size())\r
         {\r
         //### Find best match, if any\r
@@ -1283,7 +1290,7 @@ bool Deflater::compressWindow()
                     {\r
                     unsigned int pos1 = lookBack  + lookAhead;\r
                     unsigned int pos2 = windowPos + lookAhead;\r
-                    if (window[pos1] != window[pos2])\r
+                    if (windowBuf[pos1] != windowBuf[pos2])\r
                         break;\r
                     }\r
                 if (lookAhead > bestMatchLen)\r
@@ -1313,10 +1320,11 @@ bool Deflater::compressWindow()
             {\r
             //Literal encode\r
             //trace("### literal");\r
-            encodeLiteralStatic(window[windowPos]);\r
+            encodeLiteralStatic(windowBuf[windowPos]);\r
             windowPos++;\r
             }\r
         }\r
+\r
     encodeLiteralStatic(256);\r
     return true;\r
 }\r
@@ -1342,7 +1350,10 @@ bool Deflater::compress()
             iter++;\r
             }\r
         windowPos = 0;\r
-        putBits(0x01, 1); //1  -- last block\r
+        if (window.size() >= 32768)\r
+            putBits(0x00, 1); //0  -- more blocks\r
+        else\r
+            putBits(0x01, 1); //1  -- last block\r
         putBits(0x01, 2); //01 -- static trees\r
         if (!compressWindow())\r
             return false;\r
@@ -1948,6 +1959,22 @@ void ZipEntry::setUncompressedData(const std::vector<unsigned char> &val)
     uncompressedData = val;\r
 }\r
 \r
+/**\r
+ *\r
+ */\r
+unsigned long ZipEntry::getCrc()\r
+{\r
+    return crc;\r
+}\r
+\r
+/**\r
+ *\r
+ */\r
+void ZipEntry::setCrc(unsigned long val)\r
+{\r
+    crc = val;\r
+}\r
+\r
 /**\r
  *\r
  */\r
@@ -2001,13 +2028,6 @@ void ZipEntry::finish()
 \r
 \r
 \r
-/**\r
- *\r
- */\r
-unsigned long ZipEntry::getCrc()\r
-{\r
-    return crc;\r
-}\r
 \r
 /**\r
  *\r
@@ -2606,10 +2626,27 @@ bool ZipFile::readFileData()
                 }\r
             }\r
 \r
+        if (uncompressedSize != uncompBuf.size())\r
+            {\r
+            error("Size mismatch.  Received %ld, received %ld",\r
+                uncompressedSize, uncompBuf.size());\r
+            return false;\r
+            }\r
+\r
+        Crc32 crcEngine;\r
+        crcEngine.update(uncompBuf);\r
+        unsigned long crc = crcEngine.getValue();\r
+        if (crc != crc32)\r
+            {\r
+            error("Crc mismatch.  Calculated %08ux, received %08ux", crc, crc32);\r
+            return false;\r
+            }\r
+\r
         ZipEntry *ze = new ZipEntry(fileName, comment);\r
         ze->setCompressionMethod(compressionMethod);\r
         ze->setCompressedData(compBuf);\r
         ze->setUncompressedData(uncompBuf);\r
+        ze->setCrc(crc);\r
         entries.push_back(ze);\r
 \r
 \r
index 217b13171623b3b923dd364b3d15c84c632a0907..88631c997a0bb31b2d005d0e2408a7232a38cd20 100644 (file)
@@ -324,6 +324,11 @@ public:
      */\r
     virtual unsigned long getCrc();\r
 \r
+    /**\r
+     *\r
+     */\r
+    virtual void setCrc(unsigned long crc);\r
+\r
     /**\r
      *\r
      */\r