From f52229a4a64235a72e9ddf8a744907ea77616911 Mon Sep 17 00:00:00 2001 From: ShuaixinHuang <1836656514@qq.com> Date: Thu, 19 Nov 2026 02:03:26 +0800 Subject: [PATCH] fix(ntfs): reject invalid FILE_NAME namespaces (#11986) Co-authored-by: ShuaixinHuang <197200901+ShuaixinHuang@users.noreply.github.com> --- src/domain/windows/ntfsMftAttributes.test.ts | 14 ++++++++++++++ src/domain/windows/ntfsMftAttributes.ts | 7 ++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/domain/windows/ntfsMftAttributes.test.ts b/src/domain/windows/ntfsMftAttributes.test.ts index 407df84cbd..f549c86c8d 100644 --- a/src/domain/windows/ntfsMftAttributes.test.ts +++ b/src/domain/windows/ntfsMftAttributes.test.ts @@ -82,6 +82,20 @@ it.each([48, 72])( }, ); +it("rejects a FILE_NAME attribute with an undefined namespace", () => { + const value = Buffer.alloc(66); + value[65] = 4; + const result = scan(resident(0x30, value)); + expect(result).toMatchObject({ + attributeCoverage: "incomplete", + attributeIssue: { + kind: "malformed", + message: "FILE_NAME namespace is outside the NTFS range", + }, + fileNames: [], + }); +}); + it("retains fragmented and sparse mapping pairs and lossless nonresident sizes without reading a volume", () => { const attribute = nonresident(); const original = Buffer.from(attribute); diff --git a/src/domain/windows/ntfsMftAttributes.ts b/src/domain/windows/ntfsMftAttributes.ts index 0544bf1a9b..f49463fe05 100644 --- a/src/domain/windows/ntfsMftAttributes.ts +++ b/src/domain/windows/ntfsMftAttributes.ts @@ -459,11 +459,16 @@ export const readMftAttributes = ( malformed(cursor, "FILE_NAME string exceeds its value"); break; } + const namespace = record[valueOffset + 65]!; + if (namespace > 3) { + malformed(cursor, "FILE_NAME namespace is outside the NTFS range"); + break; + } fileNames.push({ fileOffset: fileOffset + valueOffset, parent: decodeMftFileReference(record.readBigUInt64LE(valueOffset)), ...readTimes(record.subarray(valueOffset + 8)), - namespace: record[valueOffset + 65]!, + namespace, name: record.toString( "utf16le", valueOffset + 66,