diff options
| author | jakob <jakob@memeware.net> | 2017-02-19 10:57:47 -0500 |
|---|---|---|
| committer | jakob <jakob@memeware.net> | 2017-02-19 10:57:47 -0500 |
| commit | 32fb7b11d83138cc288d62c1f1674d95cc94e8de (patch) | |
| tree | 290c5a27b58e24bb82bd46decba0aa5e1282e003 /src/header.c | |
| parent | 1fc6cc323dbaa5387d84630615c0d4cab0c1c5ba (diff) | |
Implemented table linked list, decompression and encryption. Tests have been improved.
Diffstat (limited to 'src/header.c')
| -rw-r--r-- | src/header.c | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/src/header.c b/src/header.c index e039447..0161775 100644 --- a/src/header.c +++ b/src/header.c @@ -28,15 +28,26 @@ static bool is_xp3(struct xp3_header *h); static bool is_supported(struct xp3_header *h); -/* Reads data from the given stream into a newly allocated xp3_header - structure. The stream is assumed to be at the header's beginning. - NULL is returned if the header contains an invalid magic number, or - if the archive's version is not supported. */ +/* Reads from the given stream into a newly allocated xp3_header + structure. NULL is returned if the header contains an invalid magic + number, or if the archive's version is not supported. */ struct xp3_header *read_header(struct stream *s) { struct xp3_header *h = malloc(sizeof(struct xp3_header)); if (h == NULL) return NULL; - stream_read(h, s, sizeof(struct xp3_header)); - if (!is_xp3(h) || !is_supported(h)) {free(h); return NULL;} + + /* The header structure can't be read into directly because of + potential alignment issues. */ + stream_read(h->magic, s, 11); + stream_read(&h->info_offset, s, sizeof(uint64_t)); + stream_read(&h->version, s, sizeof(uint32_t)); + stream_read(&h->table_size, s, sizeof(uint64_t)); + stream_read(&h->flags, s, sizeof(uint8_t)); + stream_read(&h->table_offset, s, sizeof(uint64_t)); + + if (!is_xp3(h) || !is_supported(h)) { + free(h); + return NULL; + } return h; } @@ -47,7 +58,7 @@ static bool is_xp3(struct xp3_header *h) { } -/* Checks that the archive is of XP3 version 2. */ +/* Checks that the archive's version is supported. */ static bool is_supported(struct xp3_header *h) { return h->version == 1; } |