From 7c25842bae6906de375406b99717e20807ec0ca4 Mon Sep 17 00:00:00 2001 From: ShuaixinHuang <1836656514@qq.com> Date: Thu, 19 Nov 2026 02:03:34 +0800 Subject: [PATCH] fix(ntfs): reject unaligned USN v4 extents (#11969) Co-authored-by: ShuaixinHuang <197200901+ShuaixinHuang@users.noreply.github.com> --- src/domain/windows/ntfsUsnJournal.test.ts | 14 ++++++++------ src/domain/windows/ntfsUsnJournal.ts | 1 + 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/domain/windows/ntfsUsnJournal.test.ts b/src/domain/windows/ntfsUsnJournal.test.ts index 75821a3f2d..234f68a608 100644 --- a/src/domain/windows/ntfsUsnJournal.test.ts +++ b/src/domain/windows/ntfsUsnJournal.test.ts @@ -131,13 +131,15 @@ it("bounds V4 extent delivery while retaining full coverage counts and continuat }); it.each([ - [15, 1], - [16, 65535], + [15, 1, 80], + // Both 17-byte extents fit, so only the alignment check rejects this record. + [17, 2, 104], + [16, 65535, 80], ])( - "refuses V4 stride %i / count %i before extent allocation", - (stride, count) => { - const bytes = Buffer.alloc(80); - bytes.writeUInt32LE(80); + "refuses V4 stride %i / count %i in a %i-byte record before extent allocation", + (stride, count, recordBytes) => { + const bytes = Buffer.alloc(recordBytes); + bytes.writeUInt32LE(bytes.length); bytes.writeUInt16LE(4, 4); bytes.writeUInt16LE(count, 60); bytes.writeUInt16LE(stride, 62); diff --git a/src/domain/windows/ntfsUsnJournal.ts b/src/domain/windows/ntfsUsnJournal.ts index 02c24adf22..daddf573e8 100644 --- a/src/domain/windows/ntfsUsnJournal.ts +++ b/src/domain/windows/ntfsUsnJournal.ts @@ -147,6 +147,7 @@ const readExtentRecord = ( // Validate the complete declared array before allocating the fixed-size sample. if ( extentSize < 16 || + extentSize % 8 !== 0 || extentCount > Math.floor((record.length - 64) / extentSize) ) return err({ kind: "malformed", fileOffset });