From 6df199f8e8f826abc0fb88449ece32a0976efb21 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 30 Sep 2025 01:51:18 +0100 Subject: [PATCH] Fix nextBlockPosition calculation to prevent overwriting DDT and reset offsets --- src/ddt/ddt_v2.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ddt/ddt_v2.c b/src/ddt/ddt_v2.c index 3b16927..8e3ec7a 100644 --- a/src/ddt/ddt_v2.c +++ b/src/ddt/ddt_v2.c @@ -1030,6 +1030,8 @@ void set_ddt_multi_level_v2(aaruformatContext *ctx, uint64_t sectorAddress, bool // Update nextBlockPosition to ensure future blocks don't overwrite the DDT uint64_t ddtTotalSize = sizeof(DdtHeader2) + ddtHeader.length; ctx->nextBlockPosition = (endOfFile + ddtTotalSize + alignmentMask) & ~alignmentMask; + blockOffset = ctx->nextBlockPosition; + offset = 0; TRACE("Updated nextBlockPosition after never-written DDT write to %" PRIu64, ctx->nextBlockPosition); // Free the cached table @@ -1203,6 +1205,8 @@ void set_ddt_multi_level_v2(aaruformatContext *ctx, uint64_t sectorAddress, bool // Update nextBlockPosition to ensure future blocks don't overwrite the DDT uint64_t ddtTotalSize = sizeof(DdtHeader2) + ddtHeader.length; ctx->nextBlockPosition = (endOfFile + ddtTotalSize + alignmentMask) & ~alignmentMask; + blockOffset = ctx->nextBlockPosition; + offset = 0; TRACE("Updated nextBlockPosition after DDT write to %" PRIu64, ctx->nextBlockPosition); fseek(ctx->imageStream, savedPos, SEEK_SET);