Skip to content

Commit

Permalink
Remove support for deflate from ZipParser
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
morio committed Dec 2, 2024
1 parent 0d41ffe commit 35bc338
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
24 changes: 13 additions & 11 deletions lib/ZipParser/zip_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include "zip_parser.h"

#define ZIP_PARSER_METHOD_DEFLATE_BYTE 0x08
#define ZIP_PARSER_METHOD_UNCOMPRESSED_BYTE 0x00

namespace zipparser
{
Expand All @@ -40,7 +42,6 @@ namespace zipparser
{
target = parsing_target::signature;
position = 0;
deflate = false;
filename_match = false;
crc = 0;
}
Expand All @@ -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)
Expand All @@ -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;
Expand All @@ -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)
{
Expand Down Expand Up @@ -230,10 +237,5 @@ namespace zipparser
{
return filename_match;
}

uint32_t Parser::GetCompressedSize()
{
return compressed_data_size;
}
}

5 changes: 2 additions & 3 deletions lib/ZipParser/zip_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -57,7 +57,6 @@ namespace zipparser
uint32_t uncompressed_data_size;
parsing_target target;
size_t position;
bool deflate;
uint32_t crc;

};
Expand Down
1 change: 0 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 35bc338

Please sign in to comment.