Index: src/OFMutableZIPArchiveEntry.h ================================================================== --- src/OFMutableZIPArchiveEntry.h +++ src/OFMutableZIPArchiveEntry.h @@ -90,16 +90,16 @@ OFZIPArchiveEntryCompressionMethod compressionMethod; /** * @brief The compressed size of the entry's file. */ -@property (readwrite, nonatomic) uint64_t compressedSize; +@property (readwrite, nonatomic) unsigned long long compressedSize; /** * @brief The uncompressed size of the entry's file. */ -@property (readwrite, nonatomic) uint64_t uncompressedSize; +@property (readwrite, nonatomic) unsigned long long uncompressedSize; /** * @brief The CRC32 checksum of the entry's file. */ @property (readwrite, nonatomic) uint32_t CRC32; Index: src/OFMutableZIPArchiveEntry.m ================================================================== --- src/OFMutableZIPArchiveEntry.m +++ src/OFMutableZIPArchiveEntry.m @@ -140,16 +140,16 @@ (OFZIPArchiveEntryCompressionMethod)compressionMethod { _compressionMethod = compressionMethod; } -- (void)setCompressedSize: (uint64_t)compressedSize +- (void)setCompressedSize: (unsigned long long)compressedSize { _compressedSize = compressedSize; } -- (void)setUncompressedSize: (uint64_t)uncompressedSize +- (void)setUncompressedSize: (unsigned long long)uncompressedSize { _uncompressedSize = uncompressedSize; } - (void)setCRC32: (uint32_t)CRC32 Index: src/OFZIPArchive.m ================================================================== --- src/OFZIPArchive.m +++ src/OFZIPArchive.m @@ -81,11 +81,11 @@ OF_DIRECT_MEMBERS @interface OFZIPArchiveFileReadStream: OFStream { OFStream *_stream, *_decompressedStream; OFZIPArchiveEntry *_entry; - uint64_t _toRead; + unsigned long long _toRead; uint32_t _CRC32; bool _atEndOfStream; } - (instancetype)of_initWithStream: (OFStream *)stream @@ -96,11 +96,11 @@ @interface OFZIPArchiveFileWriteStream: OFStream { OFStream *_stream; uint32_t _CRC32; @public - int64_t _bytesWritten; + unsigned long long _bytesWritten; OFMutableZIPArchiveEntry *_entry; } - (instancetype)initWithStream: (OFStream *)stream entry: (OFMutableZIPArchiveEntry *)entry; @@ -408,11 +408,11 @@ [_lastReturnedStream isKindOfClass: [OFZIPArchiveFileWriteStream class]]) { OFZIPArchiveFileWriteStream *stream = (OFZIPArchiveFileWriteStream *)_lastReturnedStream; - if (INT64_MAX - _offset < stream->_bytesWritten) + if (ULLONG_MAX - _offset < stream->_bytesWritten) @throw [OFOutOfRangeException exception]; _offset += stream->_bytesWritten; if (stream->_entry != nil) { @@ -801,11 +801,11 @@ #if SIZE_MAX >= UINT64_MAX if (length > UINT64_MAX) @throw [OFOutOfRangeException exception]; #endif - if ((uint64_t)length > _toRead) + if (length > _toRead) length = (size_t)_toRead; ret = [_decompressedStream readIntoBuffer: buffer length: length]; _toRead -= ret; @@ -884,28 +884,28 @@ #if SIZE_MAX >= INT64_MAX if (length > INT64_MAX) @throw [OFOutOfRangeException exception]; #endif - if (INT64_MAX - _bytesWritten < (int64_t)length) + if (ULLONG_MAX - _bytesWritten < length) @throw [OFOutOfRangeException exception]; @try { [_stream writeBuffer: buffer length: length]; } @catch (OFWriteFailedException *e) { OFEnsure(e.bytesWritten <= length); - _bytesWritten += (int64_t)e.bytesWritten; + _bytesWritten += e.bytesWritten; _CRC32 = OFCRC32(_CRC32, buffer, e.bytesWritten); if (e.errNo == EWOULDBLOCK || e.errNo == EAGAIN) return e.bytesWritten; @throw e; } - _bytesWritten += (int64_t)length; + _bytesWritten += length; _CRC32 = OFCRC32(_CRC32, buffer, length); return length; } @@ -912,14 +912,17 @@ - (void)close { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; + if (_bytesWritten > UINT64_MAX) + @throw [OFOutOfRangeException exception]; + [_stream writeLittleEndianInt32: 0x08074B50]; [_stream writeLittleEndianInt32: _CRC32]; - [_stream writeLittleEndianInt64: _bytesWritten]; - [_stream writeLittleEndianInt64: _bytesWritten]; + [_stream writeLittleEndianInt64: (uint64_t)_bytesWritten]; + [_stream writeLittleEndianInt64: (uint64_t)_bytesWritten]; [_stream release]; _stream = nil; _entry.CRC32 = ~_CRC32; Index: src/OFZIPArchiveEntry.h ================================================================== --- src/OFZIPArchiveEntry.h +++ src/OFZIPArchiveEntry.h @@ -106,11 +106,11 @@ OFZIPArchiveEntryAttributeCompatibility _minVersionNeeded; uint16_t _generalPurposeBitFlag; OFZIPArchiveEntryCompressionMethod _compressionMethod; uint16_t _lastModifiedFileTime, _lastModifiedFileDate; uint32_t _CRC32; - uint64_t _compressedSize, _uncompressedSize; + unsigned long long _compressedSize, _uncompressedSize; OFString *_fileName; OFData *_Nullable _extraField; OFString *_Nullable _fileComment; uint32_t _startDiskNumber; uint16_t _internalAttributes; @@ -180,16 +180,16 @@ OFZIPArchiveEntryCompressionMethod compressionMethod; /** * @brief The compressed size of the entry's file. */ -@property (readonly, nonatomic) uint64_t compressedSize; +@property (readonly, nonatomic) unsigned long long compressedSize; /** * @brief The uncompressed size of the entry's file. */ -@property (readonly, nonatomic) uint64_t uncompressedSize; +@property (readonly, nonatomic) unsigned long long uncompressedSize; /** * @brief The CRC32 checksum of the entry's file. */ @property (readonly, nonatomic) uint32_t CRC32; Index: src/OFZIPArchiveEntry.m ================================================================== --- src/OFZIPArchiveEntry.m +++ src/OFZIPArchiveEntry.m @@ -364,16 +364,16 @@ - (OFZIPArchiveEntryCompressionMethod)compressionMethod { return _compressionMethod; } -- (uint64_t)compressedSize +- (unsigned long long)compressedSize { return _compressedSize; } -- (uint64_t)uncompressedSize +- (unsigned long long)uncompressedSize { return _uncompressedSize; } - (uint32_t)CRC32 Index: utils/ofarc/ZIPArchive.m ================================================================== --- utils/ofarc/ZIPArchive.m +++ utils/ofarc/ZIPArchive.m @@ -246,11 +246,11 @@ void *pool = objc_autoreleasePoolPush(); OFString *fileName = entry.fileName; OFString *outFileName, *directory; OFStream *stream; OFFile *output; - uint64_t written = 0, size = entry.uncompressedSize; + unsigned long long written = 0, size = entry.uncompressedSize; int8_t percent = -1, newPercent; if (!all && ![files containsObject: fileName]) continue; @@ -437,15 +437,15 @@ @"file", fileName)]; entry = [OFMutableZIPArchiveEntry entryWithFileName: fileName]; size = (isDirectory ? 0 : attributes.fileSize); - if (size > INT64_MAX) + if (size < 0 || size > ULLONG_MAX) @throw [OFOutOfRangeException exception]; - entry.compressedSize = (int64_t)size; - entry.uncompressedSize = (int64_t)size; + entry.compressedSize = size; + entry.uncompressedSize = size; entry.compressionMethod = OFZIPArchiveEntryCompressionMethodNone; entry.modificationDate = attributes.fileModificationDate;