ObjFW  Check-in [816ec4d0f5]

Overview
Comment:OFLHAArchive: Correctly write directory name
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 816ec4d0f5eae59f932877ac1b2f005fd88e6c5e5af15c46a7626232ab24aa20
User & Date: js on 2018-06-17 11:03:49
Other Links: manifest | tags
Context
2018-06-17
11:19
OFLHAArchive: Write extensions check-in: 4e5688382f user: js tags: trunk
11:03
OFLHAArchive: Correctly write directory name check-in: 816ec4d0f5 user: js tags: trunk
02:54
Make GCC happy again check-in: abf95ba35e user: js tags: trunk
Changes

Modified src/OFLHAArchiveEntry.m from [24aa0ab799] to [d1563d1ec0].

266
267
268
269
270
271
272
273
274
275
276
277






278


279
280

281



282
283
284
285
286
287
288
289
290
291

			entry->_compressedSize -= size;
		}
	}
}

static void
getFileNameAndDirectoryNameForPath(OFString *path,
    of_string_encoding_t encoding,
    const char **fileName, size_t *fileNameLength,
    const char **directoryName, size_t *directoryNameLength)
{






	/* We use OFMutableData to have an autoreleased buffer. */


	OFMutableData *data = [OFMutableData
	    dataWithItems: [path cStringWithEncoding: encoding]

		    count: [path cStringLengthWithEncoding: encoding]];



	char *cString = [data items];
	size_t length = [data count];
	size_t pos = 0;

	for (size_t i = 0; i < length; i++) {
		if (cString[i] == '/' || cString[i] == '\\') {
			cString[i] = '\xFF';
			pos = i + 1;
		}
	}







|




>
>
>
>
>
>
|
>
>
|
|
>
|
>
>
>
|
|
|







266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303

			entry->_compressedSize -= size;
		}
	}
}

static void
getFileNameAndDirectoryName(OFLHAArchiveEntry *entry,
    of_string_encoding_t encoding,
    const char **fileName, size_t *fileNameLength,
    const char **directoryName, size_t *directoryNameLength)
{
	OFMutableData *data;
	char *cString;
	size_t length;
	size_t pos;

	/*
	 * We use OFMutableData to have an autoreleased buffer that we can
	 * return indirectly.
	 */
	data = [OFMutableData
	    dataWithItems: [entry->_directoryName cStringWithEncoding: encoding]
		    count: [entry->_directoryName
			       cStringLengthWithEncoding: encoding]];
	[data addItems: [entry->_fileName cStringWithEncoding: encoding]
		 count: [entry->_fileName cStringLengthWithEncoding: encoding]];

	cString = [data items];
	length = [data count];
	pos = 0;

	for (size_t i = 0; i < length; i++) {
		if (cString[i] == '/' || cString[i] == '\\') {
			cString[i] = '\xFF';
			pos = i + 1;
		}
	}
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
	uint32_t tmp32;
	size_t headerSize;

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

	getFileNameAndDirectoryNameForPath(_fileName, encoding,
	    &fileName, &fileNameLength,
	    &directoryName, &directoryNameLength);

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

	/* Length. Filled in after we're done. */







<
|







569
570
571
572
573
574
575

576
577
578
579
580
581
582
583
	uint32_t tmp32;
	size_t headerSize;

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


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

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

	/* Length. Filled in after we're done. */