From: Jonathan Dieter Date: Wed, 18 Jul 2018 16:25:03 +0000 (+0100) Subject: WARNING: File format change: flags are now compressed integer X-Git-Tag: archive/raspbian/1.1.9+ds1-1+rpi1~1^2~190 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=dfe43a78c121e0cf30684e440eb79406a417c214;p=zchunk.git WARNING: File format change: flags are now compressed integer Signed-off-by: Jonathan Dieter --- diff --git a/src/lib/header.c b/src/lib/header.c index 815dd50..78bafcf 100644 --- a/src/lib/header.c +++ b/src/lib/header.c @@ -54,30 +54,21 @@ return False; \ } -static int check_flags(zckCtx *zck, char *header, size_t *length, size_t max_length) { - if(max_length < 4) { - zck_log(ZCK_LOG_ERROR, "Read past end of header\n"); - return False; - } - zck->has_streams = header[3] & 0x01; +static int check_flags(zckCtx *zck, size_t flags) { + zck->has_streams = flags & 1; if(zck->has_streams) { zck_log(ZCK_LOG_ERROR, "This version of zchunk doesn't support streams\n"); return False; } - if((header[3] & 0xfe) != 0 || header[2] != 0 || header[1] != 0 || - header[0] != 0) { + flags = flags & (SIZE_MAX - 1); + if(flags != 0) { zck_log(ZCK_LOG_ERROR, "Unknown flags(s) set\n"); return False; } - *length += 4; return True; } static int read_header_from_file(zckCtx *zck) { - if(zck->header_length > MAX_HEADER_IN_MEM) { - - } - /* Allocate header and store any extra bytes at beginning of header */ zck->header = realloc(zck->header, zck->lead_size + zck->header_length); if(zck->header == NULL) { @@ -146,7 +137,10 @@ static int read_preface(zckCtx *zck) { length += zck->hash_type.digest_size; /* Read flags */ - if(!check_flags(zck, header+length, &length, max_length-length)) + size_t flags = 0; + if(!compint_to_size(&flags, header+length, &length, max_length)) + return False; + if(!check_flags(zck, flags)) return False; /* Setup for reading compression type */ @@ -248,12 +242,10 @@ static int preface_create(zckCtx *zck) { length += zck->hash_type.digest_size; /* Write out flags */ - memset(header + length, 0, 3); - length += 3; - /* Final byte for flags */ + size_t flags = 0; if(zck->has_streams) - header[length] &= 1; - length += 1; + flags &= 1; + compint_from_size(header+length, flags, &length); /* Write out compression type and index size */ if(!compint_from_int(header+length, zck->comp.type, &length)) { diff --git a/test/empty.c b/test/empty.c index a6b9452..79936bd 100644 --- a/test/empty.c +++ b/test/empty.c @@ -36,7 +36,7 @@ #include "zck_private.h" #include "util.h" -static char *checksum="3fbbbd3977f9e7a0660798d4823c500d0684cb8e576f65b2460af39eee65a73e"; +static char *checksum="8efaeb8e7b3d51a943353f7e6ca4a22266f18c3ef10478b20d50040f4226015d"; int main (int argc, char *argv[]) { /* Create empty zchunk file */ diff --git a/zchunk_format.txt b/zchunk_format.txt index 73deee6..6cd860e 100644 --- a/zchunk_format.txt +++ b/zchunk_format.txt @@ -38,9 +38,9 @@ Header checksum The preface: -+===============+-+-+-+-+========================+ -| Data checksum | Flags | Compression type (ci ) | -+===============+-+-+-+-+========================+ ++===============+============+========================+ +| Data checksum | Flags (ci) | Compression type (ci ) | ++===============+============+========================+ Data checksum This is the checksum of everything after the header, including the compressed @@ -48,8 +48,9 @@ Data checksum overall checksum type, *not* the chunk checksum type. Flags - 32 bits for flags. All unused flags MUST be set to 0. If a decoder sees a - flag set that it doesn't recognize, it MUST exit with an error. + This is a compressed integer containing a bitmask of the flags. All unused + flags MUST be set to 0. If a decoder sees a flag set that it doesn't + recognize, it MUST exit with an error. Current flags are: bit 0: File has data streams