Browse Source

Remove support for deflate from ZipParser

It was decided that deflate will not be supported in the initial
release of using zip file packages for firmware releases.

If the parser sees any method besides uncompressed it returns an error.
J. Morio Sakaguchi 11 months ago
parent
commit
35bc3384d7
3 changed files with 15 additions and 15 deletions
  1. 13 11
      lib/ZipParser/zip_parser.cpp
  2. 2 3
      lib/ZipParser/zip_parser.h
  3. 0 1
      platformio.ini

+ 13 - 11
lib/ZipParser/zip_parser.cpp

@@ -21,6 +21,8 @@
 
 
 #include "zip_parser.h"
 #include "zip_parser.h"
 
 
+#define ZIP_PARSER_METHOD_DEFLATE_BYTE 0x08
+#define ZIP_PARSER_METHOD_UNCOMPRESSED_BYTE 0x00
 
 
 namespace zipparser
 namespace zipparser
 {
 {
@@ -40,7 +42,6 @@ namespace zipparser
     {
     {
         target = parsing_target::signature;
         target = parsing_target::signature;
         position = 0;
         position = 0;
-        deflate = false;
         filename_match = false;
         filename_match = false;
         crc = 0;
         crc = 0;
     }
     }
@@ -64,6 +65,7 @@ namespace zipparser
 
 
         static bool matching = true;
         static bool matching = true;
         static bool central_dir = false;
         static bool central_dir = false;
+        static bool local_file_header = false;
         for (size_t idx = 0; idx < size; idx++)
         for (size_t idx = 0; idx < size; idx++)
         {
         {
             switch (target)
             switch (target)
@@ -73,21 +75,25 @@ namespace zipparser
                         break;
                         break;
                     if (position == 2 && buf[idx] == 'K')
                     if (position == 2 && buf[idx] == 'K')
                     {
                     {
+                        local_file_header = false;
                         central_dir = false;
                         central_dir = false;
                         break;
                         break;
                     }
                     }
                     if (position == 3 && buf[idx] == 0x03)
                     if (position == 3 && buf[idx] == 0x03)
+                    {
+                        local_file_header = true;
                         break;
                         break;
+                    }
                     if (position == 3 && buf[idx] == 0x01)
                     if (position == 3 && buf[idx] == 0x01)
                     {
                     {
                         central_dir = true;
                         central_dir = true;
                         break;
                         break;
                     }
                     }
-                    if (position == 4 && central_dir && buf[idx] == 0x2)
+                    if (central_dir && position == 4 && buf[idx] == 0x2)
                     {
                     {
                         return PARSE_CENTRAL_DIR;
                         return PARSE_CENTRAL_DIR;
                     }
                     }
-                    if (position == 4 && buf[idx] == 0x04)
+                    if (local_file_header &&  position == 4 && buf[idx] == 0x04)
                     {
                     {
                         position = 0;
                         position = 0;
                         target = parsing_target::version;
                         target = parsing_target::version;
@@ -112,10 +118,11 @@ namespace zipparser
                 case parsing_target::method:
                 case parsing_target::method:
                     if (++position == 1)
                     if (++position == 1)
                     {
                     {
-                        if (buf[idx] == 0x08 || buf[idx] == 0x00)
-                            deflate = buf[idx] == 0x08;
-                        else
+                        // Currently only uncompresseed files in the zip package are supported
+                        if (!buf[idx] == ZIP_PARSER_METHOD_UNCOMPRESSED_BYTE)
+                        {
                             return PARSE_UNSUPPORTED_COMPRESSION;
                             return PARSE_UNSUPPORTED_COMPRESSION;
+                        }
                     }
                     }
                     if (position == 2)
                     if (position == 2)
                     {
                     {
@@ -230,10 +237,5 @@ namespace zipparser
     {
     {
         return filename_match;
         return filename_match;
     }
     }
-
-    uint32_t Parser::GetCompressedSize()
-    {
-        return compressed_data_size;
-    }
 }
 }
 
 

+ 2 - 3
lib/ZipParser/zip_parser.h

@@ -45,8 +45,8 @@ namespace zipparser
             // \returns the number of bytes processed or -1 if an error ocurred
             // \returns the number of bytes processed or -1 if an error ocurred
             int32_t Parse(uint8_t const *buf, const size_t size);
             int32_t Parse(uint8_t const *buf, const size_t size);
             bool FoundMatch();
             bool FoundMatch();
-            uint32_t GetCompressedSize();
-            
+            inline uint32_t GetCompressedSize() {return compressed_data_size;}
+
         protected:
         protected:
             bool filename_match;
             bool filename_match;
             char const *filename;
             char const *filename;
@@ -57,7 +57,6 @@ namespace zipparser
             uint32_t uncompressed_data_size;
             uint32_t uncompressed_data_size;
             parsing_target target;
             parsing_target target;
             size_t position;
             size_t position;
-            bool deflate;
             uint32_t crc;
             uint32_t crc;
 
 
     };
     };

+ 0 - 1
platformio.ini

@@ -115,7 +115,6 @@ board_build.ldscript = ${BUILD_DIR}/rp_linker.ld ; created by src/process-linker
 framework = arduino
 framework = arduino
 lib_deps =
 lib_deps =
     SdFat=https://github.com/rabbitholecomputing/SdFat#2.2.3-gpt
     SdFat=https://github.com/rabbitholecomputing/SdFat#2.2.3-gpt
-    uzlib=https://github.com/pfalcon/uzlib
     minIni
     minIni
     SCSI2SD
     SCSI2SD
     CUEParser=https://github.com/rabbitholecomputing/CUEParser
     CUEParser=https://github.com/rabbitholecomputing/CUEParser