@@ -48,7 +48,7 @@ public static List<AttributeRecord> GetAssembledAttributes(List<FileRecordSegmen
4848
4949 if ( attribute is ResidentAttributeRecord )
5050 {
51- result . Add ( attribute ) ;
51+ result . Add ( attribute . Clone ( ) ) ;
5252 }
5353 else
5454 {
@@ -102,7 +102,7 @@ private static NonResidentAttributeRecord AssembleFragments(List<NonResidentAttr
102102 long relativeOffset = absoluteOffset - previousLCN ;
103103
104104 int runIndex = attribute . DataRunSequence . Count ;
105- attribute . DataRunSequence . AddRange ( attributeFragment . DataRunSequence ) ;
105+ attribute . DataRunSequence . AddRange ( attributeFragment . DataRunSequence . Clone ( ) ) ;
106106 attribute . DataRunSequence [ runIndex ] = new DataRun ( runLength , relativeOffset ) ;
107107 attribute . HighestVCN = attributeFragment . HighestVCN ;
108108 }
@@ -127,7 +127,7 @@ public static void SliceAttributes(List<FileRecordSegment> segments, List<Attrib
127127 if ( attribute . AttributeType == AttributeType . StandardInformation ||
128128 attribute . AttributeType == AttributeType . FileName )
129129 {
130- baseFileRecordSegment . AddAttributeRecord ( attribute ) ;
130+ baseFileRecordSegment . AddAttributeRecord ( attribute . Clone ( ) ) ;
131131 }
132132 else if ( isMftFileRecord && attribute . AttributeType == AttributeType . Data )
133133 {
@@ -163,6 +163,10 @@ public static void SliceAttributes(List<FileRecordSegment> segments, List<Attrib
163163 if ( attribute . RecordLength <= remainingLengthInCurrentSegment )
164164 {
165165 remainingLengthInCurrentSegment -= ( int ) attribute . RecordLength ;
166+ if ( attribute is ResidentAttributeRecord )
167+ {
168+ attribute = attribute . Clone ( ) ;
169+ }
166170 segments [ segmentIndex ] . AddAttributeRecord ( attribute ) ;
167171 remainingAttributes . RemoveFirst ( ) ;
168172 }
@@ -226,7 +230,7 @@ private static NonResidentAttributeRecord FitMaxNumberOfRuns(NonResidentAttribut
226230 slice . AllocatedLength = record . AllocatedLength ;
227231 slice . FileSize = record . FileSize ;
228232 slice . ValidDataLength = record . ValidDataLength ;
229- slice . DataRunSequence . Add ( dataRuns [ runIndex ] ) ;
233+ slice . DataRunSequence . Add ( dataRuns [ runIndex ] . Clone ( ) ) ;
230234 }
231235 else
232236 {
@@ -246,7 +250,7 @@ private static NonResidentAttributeRecord FitMaxNumberOfRuns(NonResidentAttribut
246250 runIndex ++ ;
247251 while ( runIndex < dataRuns . Count && sliceRecordLength + dataRuns [ runIndex ] . RecordLength <= availableLength )
248252 {
249- slice . DataRunSequence . Add ( record . DataRunSequence [ runIndex ] ) ;
253+ slice . DataRunSequence . Add ( record . DataRunSequence [ runIndex ] . Clone ( ) ) ;
250254 sliceRecordLength += dataRuns [ runIndex ] . RecordLength ;
251255 clusterCount += dataRuns [ runIndex ] . RunLength ;
252256 runIndex ++ ;
0 commit comments