Skip to content

Commit 7246bfe

Browse files
committed
NTFS: AttributeData: Extend: Bugfix: Attempted to write partial cluster that was not the last cluster when converting to non-resident
1 parent 986da13 commit 7246bfe

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

DiskAccessLibrary/FileSystems/NTFS/AttributeData/AttributeData.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2014-2018 Tal Aloni <[email protected]>. All rights reserved.
1+
/* Copyright (C) 2014-2019 Tal Aloni <[email protected]>. All rights reserved.
22
*
33
* You can redistribute this program and/or modify it under the terms of
44
* the GNU Lesser Public License as published by the Free Software Foundation,
@@ -216,6 +216,15 @@ public void Extend(ulong additionalLengthInBytes)
216216
NonResidentAttributeRecord attributeRecord = NonResidentAttributeRecord.Create(m_attributeRecord.AttributeType, m_attributeRecord.Name);
217217
NonResidentAttributeData attributeData = new NonResidentAttributeData(m_volume, null, attributeRecord);
218218
attributeData.Extend(finalDataLength);
219+
if (data.Length % m_volume.BytesPerCluster > 0)
220+
{
221+
int fillDataLength = m_volume.BytesPerCluster - (data.Length % m_volume.BytesPerCluster);
222+
if ((uint)data.Length + (uint)fillDataLength < finalDataLength)
223+
{
224+
// Only the last cluster can be partially used, if this is not the last cluster, zero-fill it
225+
data = ByteUtils.Concatenate(data, new byte[fillDataLength]);
226+
}
227+
}
219228
attributeData.WriteClusters(0, data);
220229
// Note that we overwrite the old attribute only after writing the non-resident data
221230
if (m_fileRecord != null)

0 commit comments

Comments
 (0)