Blob Blame History Raw
From ee9d4810aab95208541d2807f9d114f1d5edcee0 Mon Sep 17 00:00:00 2001
From: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
Date: Wed, 8 Sep 2021 18:39:53 +0300
Subject: [Backport ee9d4810aab9] src: Fix insertion of attr in
 ni_ins_attr_ext

Do not try to insert attribute if there is no room in record.

Reviewed-by: Kari Argillander <kari.argillander@gmail.com>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
---
 src/frecord.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/frecord.c b/src/frecord.c
index 1e1a09034f65b023872d86b866ee5b3907634506..0d00b2301a2f1fa380335ab91abd0afa53538053 100644
--- a/src/frecord.c
+++ b/src/frecord.c
@@ -953,6 +953,13 @@ static int ni_ins_attr_ext(struct ntfs_inode *ni, struct ATTR_LIST_ENTRY *le,
 			continue;
 		}
 
+		/*
+		 * Do not try to insert this attribute
+		 * if there is no room in record.
+		 */
+		if (le32_to_cpu(mi->mrec->used) + asize > sbi->record_size)
+			continue;
+
 		/* Try to insert attribute into this subrecord. */
 		attr = ni_ins_new_attr(ni, mi, le, type, name, name_len, asize,
 				       name_off, svcn, ins_le);
-- 
2.31.1