Skip LZMA properties when verifying compressed blocks.

This commit is contained in:
2025-11-23 20:55:57 +00:00
parent 90f0eba315
commit 2b98fb44d0

View File

@@ -225,7 +225,7 @@ AARU_EXPORT int32_t AARU_CALL aaruf_verify_image(void *context)
goto cleanup;
}
{
uint64_t crc_length;
const unsigned int entry_count = utarray_len(index_entries);
for(unsigned int i = 0; i < entry_count; i++)
@@ -259,8 +259,24 @@ AARU_EXPORT int32_t AARU_CALL aaruf_verify_image(void *context)
goto cleanup;
}
status = update_crc64_from_stream(ctx->imageStream, block_header.cmpLength, buffer, VERIFY_SIZE,
crc64_context, "data block");
// For LZMA compression, skip the 5-byte properties header
crc_length = block_header.cmpLength;
if(block_header.compression == Lzma || block_header.compression == LzmaClauniaSubchannelTransform)
{
// Skip LZMA properties
uint8_t props[LZMA_PROPERTIES_LENGTH];
size_t read_props = fread(props, 1, LZMA_PROPERTIES_LENGTH, ctx->imageStream);
if(read_props != LZMA_PROPERTIES_LENGTH)
{
FATAL("Could not read LZMA properties");
status = AARUF_ERROR_CANNOT_READ_BLOCK;
goto cleanup;
}
crc_length -= LZMA_PROPERTIES_LENGTH;
}
status = update_crc64_from_stream(ctx->imageStream, crc_length, buffer, VERIFY_SIZE, crc64_context,
"data block");
if(status != AARUF_STATUS_OK) goto cleanup;
if(aaruf_crc64_final(crc64_context, &crc64) != 0)
@@ -299,8 +315,24 @@ AARU_EXPORT int32_t AARU_CALL aaruf_verify_image(void *context)
goto cleanup;
}
status = update_crc64_from_stream(ctx->imageStream, ddt_header.cmpLength, buffer, VERIFY_SIZE,
crc64_context, "DDT block");
// For LZMA compression, skip the 5-byte properties header
crc_length = ddt_header.cmpLength;
if(ddt_header.compression == Lzma || ddt_header.compression == LzmaClauniaSubchannelTransform)
{
// Skip LZMA properties
uint8_t props[LZMA_PROPERTIES_LENGTH];
size_t read_props = fread(props, 1, LZMA_PROPERTIES_LENGTH, ctx->imageStream);
if(read_props != LZMA_PROPERTIES_LENGTH)
{
FATAL("Could not read LZMA properties");
status = AARUF_ERROR_CANNOT_READ_BLOCK;
goto cleanup;
}
crc_length -= LZMA_PROPERTIES_LENGTH;
}
status = update_crc64_from_stream(ctx->imageStream, crc_length, buffer, VERIFY_SIZE, crc64_context,
"data block");
if(status != AARUF_STATUS_OK) goto cleanup;
if(aaruf_crc64_final(crc64_context, &crc64) != 0)
@@ -339,8 +371,24 @@ AARU_EXPORT int32_t AARU_CALL aaruf_verify_image(void *context)
goto cleanup;
}
status = update_crc64_from_stream(ctx->imageStream, ddt2_header.cmpLength, buffer, VERIFY_SIZE,
crc64_context, "DDT2 block");
// For LZMA compression, skip the 5-byte properties header
crc_length = ddt2_header.cmpLength;
if(ddt2_header.compression == Lzma || ddt2_header.compression == LzmaClauniaSubchannelTransform)
{
// Skip LZMA properties
uint8_t props[LZMA_PROPERTIES_LENGTH];
size_t read_props = fread(props, 1, LZMA_PROPERTIES_LENGTH, ctx->imageStream);
if(read_props != LZMA_PROPERTIES_LENGTH)
{
FATAL("Could not read LZMA properties");
status = AARUF_ERROR_CANNOT_READ_BLOCK;
goto cleanup;
}
crc_length -= LZMA_PROPERTIES_LENGTH;
}
status = update_crc64_from_stream(ctx->imageStream, crc_length, buffer, VERIFY_SIZE, crc64_context,
"data block");
if(status != AARUF_STATUS_OK) goto cleanup;
if(aaruf_crc64_final(crc64_context, &crc64) != 0)
@@ -386,8 +434,8 @@ AARU_EXPORT int32_t AARU_CALL aaruf_verify_image(void *context)
goto cleanup;
}
status = update_crc64_from_stream(ctx->imageStream, tracks_bytes, buffer, VERIFY_SIZE,
crc64_context, "tracks block");
status = update_crc64_from_stream(ctx->imageStream, tracks_bytes, buffer, VERIFY_SIZE, crc64_context,
"tracks block");
if(status != AARUF_STATUS_OK) goto cleanup;
if(aaruf_crc64_final(crc64_context, &crc64) != 0)
@@ -415,7 +463,6 @@ AARU_EXPORT int32_t AARU_CALL aaruf_verify_image(void *context)
break;
}
}
}
status = AARUF_STATUS_OK;