Skip to content

Commit

Permalink
.. format
Browse files Browse the repository at this point in the history
  • Loading branch information
gdraheim committed Feb 29, 2024
1 parent c73fb11 commit b47aea7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
8 changes: 4 additions & 4 deletions zzip/fetch.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,10 @@ __zzip_set64(zzip_byte_t* s, uint64_t v);
((void*) (zzip_disk_trailer_to_comment(__p) + zzip_disk_trailer_comment(__p)))

#define zzip_use_file_header_zip64_offset 0
#define zzip_extra_zip64_csize(__p) ((zzip_size_t) zzip_extra_zip64_get_csize(__p))
#define zzip_extra_zip64_usize(__p) ((zzip_size_t) zzip_extra_zip64_get_usize(__p))
#define zzip_extra_zip64_offset(__p) ((zzip_off_t) zzip_extra_zip64_get_offset(__p))
#define zzip_extra_zip64_diskstart(__p) ((zzip_size_t) zzip_extra_zip64_get_diskstart(__p))
#define zzip_extra_zip64_csize(__p) ((zzip_size_t) zzip_extra_zip64_get_csize(__p))
#define zzip_extra_zip64_usize(__p) ((zzip_size_t) zzip_extra_zip64_get_usize(__p))
#define zzip_extra_zip64_offset(__p) ((zzip_off_t) zzip_extra_zip64_get_offset(__p))
#define zzip_extra_zip64_diskstart(__p) ((zzip_size_t) zzip_extra_zip64_get_diskstart(__p))

#define zzip_disk64_locator_rootseek(__p) ((zzip_off64_t) zzip_disk64_locator_get_rootseek(__p))

Expand Down
25 changes: 14 additions & 11 deletions zzip/mmapped.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ zzip_disk_entry_to_file_header(ZZIP_DISK* disk, struct zzip_disk_entry* entry)
{
zzip_byte_t* const ptr = disk->buffer + zzip_disk_entry_fileoffset(entry);
zzip_byte_t* const end = ptr + sizeof(struct zzip_file_header);
if (disk->buffer > ptr || end >= disk->endbuf || (void*)end <= NULL) {
if (disk->buffer > ptr || end >= disk->endbuf || (void*) end <= NULL) {
debug2("file header: offset out of bounds (0x%llx)", (long long unsigned) (disk->buffer));
errno = EBADMSG;
return 0;
Expand Down Expand Up @@ -625,8 +625,8 @@ zzip_disk_entry_fopen(ZZIP_DISK* disk, ZZIP_DISK_ENTRY* entry)
}

___ /* a ZIP64 extended block may follow. */
size_t csize = zzip_file_header_csize(header);
zzip_byte_t* start = zzip_file_header_to_data(header);
size_t csize = zzip_file_header_csize(header);
zzip_byte_t* start = zzip_file_header_to_data(header);
if (csize == 0xFFFFu) {
struct zzip_extra_zip64* zip64 =
(struct zzip_extra_zip64*) zzip_file_header_to_extras(header);
Expand All @@ -635,24 +635,27 @@ zzip_disk_entry_fopen(ZZIP_DISK* disk, ZZIP_DISK_ENTRY* entry)
}
}

if (((unsigned long)start) & 0xFFFFu == 0xFFFFu) {
/* actually the ZIP64 rootseek in the central directory should have updated the
if (((unsigned long) start) & 0xFFFFu == 0xFFFFu) {
/* actually the ZIP64 rootseek in the central directory should have updated the
header start with the data portion to follow right behind it. The usage of
this field in a local file header is wrong on a number of levels. Specifically
that the zip64 extended field value points to yet another header but it is
actually used to point to the actual data portion instead. */
actually used to point to the actual data portion instead. Disabled by default. */
struct zzip_extra_zip64* zip64 =
(struct zzip_extra_zip64*) zzip_file_header_to_extras(header);
if (ZZIP_EXTRA_ZIP64_CHECK(zip64)) {
zzip_off64_t offset = zzip_extra_zip64_offset(zip64); /* offset of local header record */
zzip_off64_t offset =
zzip_extra_zip64_offset(zip64); /* offset of local header record */
if (offset && zzip_use_file_header_zip64_offset) {
start = disk->buffer + offset; /* but points directly to the data portion */
if (disk->buffer > start || start+csize >= disk->endbuf) {
debug2("file start: offset out of bounds (0x%llx)", (long long unsigned) (offset));
start = disk->buffer + offset; /* but points directly to the data portion */
if (disk->buffer > start || start + csize >= disk->endbuf) {
debug2("file start: offset out of bounds (0x%llx)",
(long long unsigned) (offset));
errno = EBADMSG;
return 0;
}
} else {
}
else {
debug1("file start: no zip64 local offset");
errno = EBADMSG;
return 0;
Expand Down

0 comments on commit b47aea7

Please sign in to comment.