From e39e803c919c99247a5882eb52be99874b6f39c0 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 28 Sep 2025 18:42:33 +0100 Subject: [PATCH] Align end of file to block boundary for improved data integrity --- src/ddt/ddt_v2.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ddt/ddt_v2.c b/src/ddt/ddt_v2.c index 7b48d29..f669729 100644 --- a/src/ddt/ddt_v2.c +++ b/src/ddt/ddt_v2.c @@ -910,8 +910,10 @@ void set_ddt_multi_level_v2(aaruformatContext *ctx, uint64_t sectorAddress, bool currentPos = ftell(ctx->imageStream); fseek(ctx->imageStream, 0, SEEK_END); endOfFile = ftell(ctx->imageStream); - endOfFile = endOfFile / (1 << ctx->userDataDdtHeader.blockAlignmentShift) * - (1 << ctx->userDataDdtHeader.blockAlignmentShift); + + // Align to block boundary + uint64_t alignmentMask = (1ULL << ctx->userDataDdtHeader.blockAlignmentShift) - 1; + endOfFile = (endOfFile + alignmentMask) & ~alignmentMask; fseek(ctx->imageStream, endOfFile, SEEK_SET); // Prepare DDT header for the cached table