From 89b367941e12b1163afa517eeddca1b5ecd2a054 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sat, 4 Feb 2023 16:30:48 +0100 Subject: libtar: some minor cleanups - Use is_memory_zero from libutil - Move checksum update function to tar writer code - Move checksum verify function to tar reader code - Only export the function to compute the checksum Signed-off-by: David Oberhollenzer --- lib/tar/src/read_header.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'lib/tar/src/read_header.c') diff --git a/lib/tar/src/read_header.c b/lib/tar/src/read_header.c index ea4873b..219c9fb 100644 --- a/lib/tar/src/read_header.c +++ b/lib/tar/src/read_header.c @@ -10,11 +10,14 @@ #include #include -static bool is_zero_block(const tar_header_t *hdr) +static bool is_checksum_valid(const tar_header_t *hdr) { - const unsigned char *ptr = (const unsigned char *)hdr; + sqfs_u64 read_chksum; - return ptr[0] == '\0' && memcmp(ptr, ptr + 1, sizeof(*hdr) - 1) == 0; + if (read_octal(hdr->chksum, sizeof(hdr->chksum), &read_chksum)) + return false; + + return read_chksum == tar_compute_checksum(hdr); } static int check_version(const tar_header_t *hdr) @@ -179,7 +182,7 @@ int read_header(istream_t *fp, tar_header_decoded_t *out) if ((size_t)ret < sizeof(hdr)) goto out_eof; - if (is_zero_block(&hdr)) { + if (is_memory_zero(&hdr, sizeof(hdr))) { if (prev_was_zero) goto out_eof; prev_was_zero = true; -- cgit v1.2.3