4 Commits

4 changed files with 236 additions and 189 deletions

View File

@@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"> <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata> <metadata>
<id>libaaruformat</id> <id>libaaruformat</id>
<version>1.0.0-alpha.10</version> <version>1.0.0-alpha.12</version>
<description>Library for management of AaruFormat images.</description> <description>Library for management of AaruFormat images.</description>
<authors>claunia</authors> <authors>claunia</authors>
<projectUrl>https://github.com/aaru-dps/libaaruformat</projectUrl> <projectUrl>https://github.com/aaru-dps/libaaruformat</projectUrl>

View File

@@ -297,7 +297,7 @@ AARU_EXPORT int32_t AARU_CALL aaruf_read_sector(void *context, const uint64_t se
return AARUF_ERROR_NOT_AARUFORMAT; return AARUF_ERROR_NOT_AARUFORMAT;
} }
if(negative && sector_address > ctx->user_data_ddt_header.negative - 1) if(negative && sector_address > ctx->user_data_ddt_header.negative)
{ {
FATAL("Sector address out of bounds"); FATAL("Sector address out of bounds");
@@ -868,7 +868,7 @@ AARU_EXPORT int32_t AARU_CALL aaruf_read_sector_long(void *context, const uint64
return AARUF_ERROR_NOT_AARUFORMAT; return AARUF_ERROR_NOT_AARUFORMAT;
} }
if(negative && sector_address > ctx->user_data_ddt_header.negative - 1) if(negative && sector_address > ctx->user_data_ddt_header.negative)
{ {
FATAL("Sector address out of bounds"); FATAL("Sector address out of bounds");
@@ -1509,7 +1509,7 @@ AARU_EXPORT int32_t AARU_CALL aaruf_read_sector_tag(const void *context, const u
return AARUF_ERROR_NOT_AARUFORMAT; return AARUF_ERROR_NOT_AARUFORMAT;
} }
if(negative && sector_address > ctx->user_data_ddt_header.negative - 1) if(negative && sector_address > ctx->user_data_ddt_header.negative)
{ {
FATAL("Sector address out of bounds"); FATAL("Sector address out of bounds");

View File

@@ -225,7 +225,7 @@ AARU_EXPORT int32_t AARU_CALL aaruf_verify_image(void *context)
goto cleanup; goto cleanup;
} }
{ uint64_t crc_length;
const unsigned int entry_count = utarray_len(index_entries); const unsigned int entry_count = utarray_len(index_entries);
for(unsigned int i = 0; i < entry_count; i++) 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; goto cleanup;
} }
status = update_crc64_from_stream(ctx->imageStream, block_header.cmpLength, buffer, VERIFY_SIZE, // For LZMA compression, skip the 5-byte properties header
crc64_context, "data block"); 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(status != AARUF_STATUS_OK) goto cleanup;
if(aaruf_crc64_final(crc64_context, &crc64) != 0) 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; goto cleanup;
} }
status = update_crc64_from_stream(ctx->imageStream, ddt_header.cmpLength, buffer, VERIFY_SIZE, // For LZMA compression, skip the 5-byte properties header
crc64_context, "DDT block"); 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(status != AARUF_STATUS_OK) goto cleanup;
if(aaruf_crc64_final(crc64_context, &crc64) != 0) 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; goto cleanup;
} }
status = update_crc64_from_stream(ctx->imageStream, ddt2_header.cmpLength, buffer, VERIFY_SIZE, // For LZMA compression, skip the 5-byte properties header
crc64_context, "DDT2 block"); 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(status != AARUF_STATUS_OK) goto cleanup;
if(aaruf_crc64_final(crc64_context, &crc64) != 0) 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; goto cleanup;
} }
status = update_crc64_from_stream(ctx->imageStream, tracks_bytes, buffer, VERIFY_SIZE, status = update_crc64_from_stream(ctx->imageStream, tracks_bytes, buffer, VERIFY_SIZE, crc64_context,
crc64_context, "tracks block"); "tracks block");
if(status != AARUF_STATUS_OK) goto cleanup; if(status != AARUF_STATUS_OK) goto cleanup;
if(aaruf_crc64_final(crc64_context, &crc64) != 0) if(aaruf_crc64_final(crc64_context, &crc64) != 0)
@@ -415,7 +463,6 @@ AARU_EXPORT int32_t AARU_CALL aaruf_verify_image(void *context)
break; break;
} }
} }
}
status = AARUF_STATUS_OK; status = AARUF_STATUS_OK;

View File

@@ -130,7 +130,7 @@ AARU_EXPORT int32_t AARU_CALL aaruf_write_sector(void *context, uint64_t sector_
return AARUF_READ_ONLY; return AARUF_READ_ONLY;
} }
if(negative && sector_address > ctx->user_data_ddt_header.negative - 1) if(negative && sector_address > ctx->user_data_ddt_header.negative)
{ {
FATAL("Sector address out of bounds"); FATAL("Sector address out of bounds");
@@ -569,7 +569,7 @@ AARU_EXPORT int32_t AARU_CALL aaruf_write_sector_long(void *context, uint64_t se
return AARUF_READ_ONLY; return AARUF_READ_ONLY;
} }
if(negative && sector_address > ctx->user_data_ddt_header.negative - 1) if(negative && sector_address > ctx->user_data_ddt_header.negative)
{ {
FATAL("Sector address out of bounds"); FATAL("Sector address out of bounds");
@@ -2101,7 +2101,7 @@ AARU_EXPORT int32_t AARU_CALL aaruf_write_sector_tag(void *context, const uint64
return AARUF_READ_ONLY; return AARUF_READ_ONLY;
} }
if(negative && sector_address > ctx->user_data_ddt_header.negative - 1) if(negative && sector_address > ctx->user_data_ddt_header.negative)
{ {
FATAL("Sector address out of bounds"); FATAL("Sector address out of bounds");