ObjFW  Diff

Differences From Artifact [fa0ccd29a1]:

To Artifact [2adb105405]:


196
197
198
199
200
201
202
















203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221



222
223
224
225
226
227
228
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+



















+
+
+








	[entry->_modificationDate release];
	entry->_modificationDate = nil;

	entry->_modificationDate = [[OFDate alloc]
	    initWithTimeIntervalSince1970: modificationDate];
}

static void
parseFileSizeExtension(OFLHAArchiveEntry *entry, OFData *extension,
    OFStringEncoding encoding)
{
	uint64_t tmp;

	if (extension.count != 17)
		@throw [OFInvalidFormatException exception];

	memcpy(&tmp, (char *)extension.items + 1, 8);
	entry->_compressedSize = OFFromLittleEndian64(tmp);

	memcpy(&tmp, (char *)extension.items + 9, 8);
	entry->_uncompressedSize = OFFromLittleEndian64(tmp);
}

static bool
parseExtension(OFLHAArchiveEntry *entry, OFData *extension,
    OFStringEncoding encoding, bool allowFileName)
{
	void (*function)(OFLHAArchiveEntry *, OFData *, OFStringEncoding) =
	    NULL;

	switch (*(char *)[extension itemAtIndex: 0]) {
	case 0x01:
		if (allowFileName)
			function = parseFileNameExtension;
		break;
	case 0x02:
		function = parseDirectoryNameExtension;
		break;
	case 0x3F:
		function = parseCommentExtension;
		break;
	case 0x42:
		function = parseFileSizeExtension;
		break;
	case 0x50:
		function = parsePermissionsExtension;
		break;
	case 0x51:
		function = parseGIDUIDExtension;
		break;
	case 0x52:
597
598
599
600
601
602
603

604
605
606
607
608
609
610
611
612
613
614
615

616
617
618
619
620
621
622
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634

635
636
637
638
639
640
641
642







+











-
+







{
	void *pool = objc_autoreleasePoolPush();
	OFMutableData *data = [OFMutableData dataWithCapacity: 24];
	const char *fileName, *directoryName;
	size_t fileNameLength, directoryNameLength;
	uint16_t tmp16;
	uint32_t tmp32;
	uint64_t tmp64;
	size_t headerSize;

	if ([_compressionMethod cStringLengthWithEncoding:
	    OFStringEncodingASCII] != 5)
		@throw [OFInvalidArgumentException exception];

	getFileNameAndDirectoryName(self, encoding, &fileName, &fileNameLength,
	    &directoryName, &directoryNameLength);

	if (fileNameLength > UINT16_MAX - 3 ||
	    directoryNameLength > UINT16_MAX - 3 ||
	    _compressedSize > UINT32_MAX || _uncompressedSize > UINT32_MAX)
	    _compressedSize > UINT64_MAX || _uncompressedSize > UINT64_MAX)
		@throw [OFOutOfRangeException exception];

	/* Length. Filled in after we're done. */
	[data increaseCountBy: 2];

	[data addItems: [_compressionMethod
			    cStringWithEncoding: OFStringEncodingASCII]
673
674
675
676
677
678
679














680
681
682
683
684
685
686
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720







+
+
+
+
+
+
+
+
+
+
+
+
+
+







		tmp16 = OFToLittleEndian16((uint16_t)fileCommentLength + 3);
		[data addItems: &tmp16 count: sizeof(tmp16)];
		[data addItem: "\x3F"];
		[data addItems: [_fileComment cStringWithEncoding: encoding]
			 count: fileCommentLength];
	}

	/*
	 * Always include the file size extension, as the header can be written
	 * with size 0 initially and then rewritten with the actual size in
	 * case the data to be archived is being streamed - but for that we
	 * need to make sure we always have the space.
	 */
	tmp16 = OFToLittleEndian16(19);
	[data addItems: &tmp16 count: sizeof(tmp16)];
	[data addItem: "\x42"];
	tmp64 = OFToLittleEndian64(_compressedSize);
	[data addItems: &tmp64 count: sizeof(tmp64)];
	tmp64 = OFToLittleEndian64(_uncompressedSize);
	[data addItems: &tmp64 count: sizeof(tmp64)];

	if (_POSIXPermissions != nil) {
		tmp16 = OFToLittleEndian16(5);
		[data addItems: &tmp16 count: sizeof(tmp16)];
		[data addItem: "\x50"];

		tmp16 =
		    OFToLittleEndian16(_POSIXPermissions.unsignedShortValue);