ObjFW  Diff

Differences From Artifact [b22fa20c14]:

To Artifact [728d6fb127]:


23
24
25
26
27
28
29

30
31
32
33
34
35
36
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37







+







#import "OFString.h"
#import "OFData.h"
#import "OFDate.h"
#import "OFStream.h"

#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFOutOfRangeException.h"

extern uint32_t of_zip_archive_read_field32(const uint8_t **, uint16_t *);
extern uint64_t of_zip_archive_read_field64(const uint8_t **, uint16_t *);

OFString *
of_zip_archive_entry_version_to_string(uint16_t version)
{
153
154
155
156
157
158
159





160



161
162
163
164
165
166
167
154
155
156
157
158
159
160
161
162
163
164
165

166
167
168
169
170
171
172
173
174
175







+
+
+
+
+
-
+
+
+







}

- initWithFileName: (OFString *)fileName
{
	self = [super init];

	@try {
		void *pool = objc_autoreleasePoolPush();

		if ([fileName UTF8StringLength] > UINT16_MAX)
			@throw [OFOutOfRangeException exception];

		_fileName = [_fileName copy];
		_fileName = [fileName copy];

		objc_autoreleasePoolPop(pool);
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}
225
226
227
228
229
230
231
232

233
234
235
236
237
238
239
233
234
235
236
237
238
239

240
241
242
243
244
245
246
247







-
+







				_localFileHeaderOffset =
				    of_zip_archive_read_field64(&ZIP64,
				    &ZIP64Size);
			if (_startDiskNumber == 0xFFFF)
				_startDiskNumber = of_zip_archive_read_field32(
				    &ZIP64, &ZIP64Size);

			if (ZIP64Size > 0)
			if (ZIP64Size > 0 || _localFileHeaderOffset < 0)
				@throw [OFInvalidFormatException exception];
		}

		objc_autoreleasePoolPop(pool);
	} @catch (id e) {
		[self release];
		@throw e;
277
278
279
280
281
282
283


284
285
286
287
288
289
290
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300







+
+







		copy->_internalAttributes = _internalAttributes;
		copy->_versionSpecificAttributes = _versionSpecificAttributes;
		copy->_localFileHeaderOffset = _localFileHeaderOffset;
	} @catch (id e) {
		[copy release];
		@throw e;
	}

	return copy;
}

- (OFString *)fileName
{
	return _fileName;
}

398
399
400
401
402
403
404














































405
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461







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


	[ret retain];

	objc_autoreleasePoolPop(pool);

	return [ret autorelease];
}

- (uint64_t)of_writeToStream: (OFStream *)stream
{
	void *pool;
	uint64_t size = 0;

	if (_compressedSize > UINT32_MAX ||
	    _uncompressedSize > UINT32_MAX ||
	    _localFileHeaderOffset > UINT32_MAX)
		@throw [OFOutOfRangeException exception];

	pool = objc_autoreleasePoolPush();

	[stream writeLittleEndianInt32: 0x02014B50];
	[stream writeLittleEndianInt16: _versionMadeBy];
	[stream writeLittleEndianInt16: _minVersionNeeded];
	[stream writeLittleEndianInt16: _generalPurposeBitFlag];
	[stream writeLittleEndianInt16: _compressionMethod];
	[stream writeLittleEndianInt16: _lastModifiedFileTime];
	[stream writeLittleEndianInt16: _lastModifiedFileDate];
	[stream writeLittleEndianInt32: _CRC32];
	[stream writeLittleEndianInt32: (uint32_t)_compressedSize];
	[stream writeLittleEndianInt32: (uint32_t)_uncompressedSize];
	[stream writeLittleEndianInt16: (uint16_t)[_fileName UTF8StringLength]];
	[stream writeLittleEndianInt16: (uint16_t)[_extraField count]];
	[stream writeLittleEndianInt16:
	    (uint16_t)[_fileComment UTF8StringLength]];
	[stream writeLittleEndianInt16: _startDiskNumber];
	[stream writeLittleEndianInt16: _internalAttributes];
	[stream writeLittleEndianInt32: _versionSpecificAttributes];
	[stream writeLittleEndianInt32: (uint32_t)_localFileHeaderOffset];
	size += (4 + (6 * 2) + (3 * 4) + (5 * 2) + (2 * 4));

	[stream writeString: _fileName];
	if (_extraField != nil)
		[stream writeData: _extraField];
	if (_fileComment != nil)
		[stream writeString: _fileComment];
	size += (uint64_t)[_fileName UTF8StringLength] +
	    (uint64_t)[_extraField count] +
	    (uint64_t)[_fileComment UTF8StringLength];

	objc_autoreleasePoolPop(pool);

	return size;
}
@end