Forráskód Böngészése

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 hónapja
szülő
commit
35bc3384d7
3 módosított fájl, 15 hozzáadás és 15 törlés
  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"
 
+#define ZIP_PARSER_METHOD_DEFLATE_BYTE 0x08
+#define ZIP_PARSER_METHOD_UNCOMPRESSED_BYTE 0x00
 
 namespace zipparser
 {
@@ -40,7 +42,6 @@ namespace zipparser
     {
         target = parsing_target::signature;
         position = 0;
-        deflate = false;
         filename_match = false;
         crc = 0;
     }
@@ -64,6 +65,7 @@ namespace zipparser
 
         static bool matching = true;
         static bool central_dir = false;
+        static bool local_file_header = false;
         for (size_t idx = 0; idx < size; idx++)
         {
             switch (target)
@@ -73,21 +75,25 @@ namespace zipparser
                         break;
                     if (position == 2 && buf[idx] == 'K')
                     {
+                        local_file_header = false;
                         central_dir = false;
                         break;
                     }
                     if (position == 3 && buf[idx] == 0x03)
+                    {
+                        local_file_header = true;
                         break;
+                    }
                     if (position == 3 && buf[idx] == 0x01)
                     {
                         central_dir = true;
                         break;
                     }
-                    if (position == 4 && central_dir && buf[idx] == 0x2)
+                    if (central_dir && position == 4 && buf[idx] == 0x2)
                     {
                         return PARSE_CENTRAL_DIR;
                     }
-                    if (position == 4 && buf[idx] == 0x04)
+                    if (local_file_header &&  position == 4 && buf[idx] == 0x04)
                     {
                         position = 0;
                         target = parsing_target::version;
@@ -112,10 +118,11 @@ namespace zipparser
                 case parsing_target::method:
                     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;
+                        }
                     }
                     if (position == 2)
                     {
@@ -230,10 +237,5 @@ namespace zipparser
     {
         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
             int32_t Parse(uint8_t const *buf, const size_t size);
             bool FoundMatch();
-            uint32_t GetCompressedSize();
-            
+            inline uint32_t GetCompressedSize() {return compressed_data_size;}
+
         protected:
             bool filename_match;
             char const *filename;
@@ -57,7 +57,6 @@ namespace zipparser
             uint32_t uncompressed_data_size;
             parsing_target target;
             size_t position;
-            bool deflate;
             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
 lib_deps =
     SdFat=https://github.com/rabbitholecomputing/SdFat#2.2.3-gpt
-    uzlib=https://github.com/pfalcon/uzlib
     minIni
     SCSI2SD
     CUEParser=https://github.com/rabbitholecomputing/CUEParser