ObjFW  Check-in [8333373867]

Overview
Comment:OF{LHA,Tar}Archive: Fix skipping over entries
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 83333738674100ce92c826bb0f33feb6f6952c9db805fe0729090441909ce340
User & Date: js on 2018-07-08 18:00:24
Other Links: manifest | tags
Context
2018-07-08
19:42
OFDNSResolver: Paths for hosts file on more OSes check-in: 418965bae3 user: js tags: trunk
18:00
OF{LHA,Tar}Archive: Fix skipping over entries check-in: 8333373867 user: js tags: trunk
12:07
Initial code for OFDNSResolver check-in: dd375b6d4e user: js tags: trunk
Changes

Modified src/OFLHAArchive.m from [6e9b4cb571] to [164823b060].

41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
@interface OFLHAArchive_FileReadStream: OFStream <OFReadyForReadingObserving>
{
	OF_KINDOF(OFStream *) _stream;
	OF_KINDOF(OFStream *) _decompressedStream;
	OFLHAArchiveEntry *_entry;
	uint32_t _toRead, _bytesConsumed;
	uint16_t _CRC16;
	bool _atEndOfStream;
}

- (instancetype)of_initWithStream: (OF_KINDOF(OFStream *))stream
			    entry: (OFLHAArchiveEntry *)entry;
- (void)of_skip;
@end








|







41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
@interface OFLHAArchive_FileReadStream: OFStream <OFReadyForReadingObserving>
{
	OF_KINDOF(OFStream *) _stream;
	OF_KINDOF(OFStream *) _decompressedStream;
	OFLHAArchiveEntry *_entry;
	uint32_t _toRead, _bytesConsumed;
	uint16_t _CRC16;
	bool _atEndOfStream, _skipped;
}

- (instancetype)of_initWithStream: (OF_KINDOF(OFStream *))stream
			    entry: (OFLHAArchiveEntry *)entry;
- (void)of_skip;
@end

367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
}

- (void)of_skip
{
	OF_KINDOF(OFStream *) stream;
	uint32_t toRead;

	if (_stream == nil || _toRead == 0)
		return;

	stream = _stream;
	toRead = _toRead;

	/*
	 * Get the number of consumed bytes and directly read from the







|







367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
}

- (void)of_skip
{
	OF_KINDOF(OFStream *) stream;
	uint32_t toRead;

	if (_stream == nil || _skipped)
		return;

	stream = _stream;
	toRead = _toRead;

	/*
	 * Get the number of consumed bytes and directly read from the
405
406
407
408
409
410
411

412
413
414
415
416
417
418

			toRead -= [stream readIntoBuffer: buffer
						  length: min];
		}
	}

	_toRead = 0;

}

- (void)close
{
	[self of_skip];

	[_stream release];







>







405
406
407
408
409
410
411
412
413
414
415
416
417
418
419

			toRead -= [stream readIntoBuffer: buffer
						  length: min];
		}
	}

	_toRead = 0;
	_skipped = true;
}

- (void)close
{
	[self of_skip];

	[_stream release];

Modified src/OFTarArchive.m from [9cb41be19d] to [641014739a].

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#import "OFWriteFailedException.h"

@interface OFTarArchive_FileReadStream: OFStream <OFReadyForReadingObserving>
{
	OFTarArchiveEntry *_entry;
	OF_KINDOF(OFStream *) _stream;
	uint64_t _toRead;
	bool _atEndOfStream;
}

- (instancetype)of_initWithStream: (OFStream *)stream
			    entry: (OFTarArchiveEntry *)entry;
- (void)of_skip;
@end








|







35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#import "OFWriteFailedException.h"

@interface OFTarArchive_FileReadStream: OFStream <OFReadyForReadingObserving>
{
	OFTarArchiveEntry *_entry;
	OF_KINDOF(OFStream *) _stream;
	uint64_t _toRead;
	bool _atEndOfStream, _skipped;
}

- (instancetype)of_initWithStream: (OFStream *)stream
			    entry: (OFTarArchiveEntry *)entry;
- (void)of_skip;
@end

357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
	_stream = nil;

	[super close];
}

- (void)of_skip
{
	if (_stream == nil || _toRead == 0)
		return;

	if ([_stream isKindOfClass: [OFSeekableStream class]] &&
	    _toRead <= INT64_MAX && (of_offset_t)_toRead == (int64_t)_toRead) {
		uint64_t size;

		[_stream seekToOffset: (of_offset_t)_toRead







|







357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
	_stream = nil;

	[super close];
}

- (void)of_skip
{
	if (_stream == nil || _skipped)
		return;

	if ([_stream isKindOfClass: [OFSeekableStream class]] &&
	    _toRead <= INT64_MAX && (of_offset_t)_toRead == (int64_t)_toRead) {
		uint64_t size;

		[_stream seekToOffset: (of_offset_t)_toRead
396
397
398
399
400
401
402


403
404
405
406
407
408
409

		size = [_entry size];

		if (size % 512 != 0)
			[_stream readIntoBuffer: buffer
				    exactLength: (size_t)(512 - (size % 512))];
	}


}
@end

@implementation OFTarArchive_FileWriteStream
- (instancetype)of_initWithStream: (OF_KINDOF(OFStream *))stream
			    entry: (OFTarArchiveEntry *)entry
{







>
>







396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411

		size = [_entry size];

		if (size % 512 != 0)
			[_stream readIntoBuffer: buffer
				    exactLength: (size_t)(512 - (size % 512))];
	}

	_skipped = true;
}
@end

@implementation OFTarArchive_FileWriteStream
- (instancetype)of_initWithStream: (OF_KINDOF(OFStream *))stream
			    entry: (OFTarArchiveEntry *)entry
{

Modified src/OFTarArchiveEntry.m from [df56ebf01c] to [eeb02938ee].

265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280

- (OFString *)description
{
	void *pool = objc_autoreleasePoolPush();
	OFString *ret = [OFString stringWithFormat: @"<%@:\n"
	     @"\tFile name = %@\n"
	     @"\tMode = %06o\n"
	     @"\tUID = %u\n",
	     @"\tGID = %u\n",
	     @"\tSize = %" PRIu64 @"\n"
	     @"\tModification date = %@\n"
	     @"\tType = %u\n"
	     @"\tTarget file name = %@\n"
	     @"\tOwner = %@\n"
	     @"\tGroup = %@\n"
	     @"\tDevice major = %" PRIu32 @"\n"







|
|







265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280

- (OFString *)description
{
	void *pool = objc_autoreleasePoolPush();
	OFString *ret = [OFString stringWithFormat: @"<%@:\n"
	     @"\tFile name = %@\n"
	     @"\tMode = %06o\n"
	     @"\tUID = %u\n"
	     @"\tGID = %u\n"
	     @"\tSize = %" PRIu64 @"\n"
	     @"\tModification date = %@\n"
	     @"\tType = %u\n"
	     @"\tTarget file name = %@\n"
	     @"\tOwner = %@\n"
	     @"\tGroup = %@\n"
	     @"\tDevice major = %" PRIu32 @"\n"