From 7db52bbe66d5dabb38a7b1015c85d52227ee0a60 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 12 Oct 2022 16:20:43 +0100 Subject: [PATCH] Fix handling CRC64 of data blocks with length 0. --- src/open.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/open.c b/src/open.c index 0d31be1..5a5040b 100644 --- a/src/open.c +++ b/src/open.c @@ -387,19 +387,22 @@ void* aaruf_open(const char* filepath) break; } - crc64 = aaruf_crc64_data(data, blockHeader.length); - - // Due to how C# wrote it, it is effectively reversed - if(ctx->header.imageMajorVersion <= AARUF_VERSION) crc64 = bswap_64(crc64); - - if(crc64 != blockHeader.crc64) + if(blockHeader.length > 0) { - fprintf(stderr, - "libaaruformat: Incorrect CRC found: 0x%" PRIx64 " found, expected 0x%" PRIx64 - ", continuing...\n", - crc64, - blockHeader.crc64); - break; + crc64 = aaruf_crc64_data(data, blockHeader.length); + + // Due to how C# wrote it, it is effectively reversed + if(ctx->header.imageMajorVersion <= AARUF_VERSION) crc64 = bswap_64(crc64); + + if(crc64 != blockHeader.crc64) + { + fprintf(stderr, + "libaaruformat: Incorrect CRC found: 0x%" PRIx64 " found, expected 0x%" PRIx64 + ", continuing...\n", + crc64, + blockHeader.crc64); + break; + } } // Check if it's not a media tag, but a sector tag, and fill the appropriate table then