Index: src/OFLHAArchive.m ================================================================== --- src/OFLHAArchive.m +++ src/OFLHAArchive.m @@ -44,11 +44,11 @@ OF_DIRECT_MEMBERS @interface OFLHAArchiveFileReadStream: OFStream { OFStream *_stream, *_decompressedStream; OFLHAArchiveEntry *_entry; - uint32_t _toRead, _bytesConsumed; + unsigned long long _toRead; uint16_t _CRC16; bool _atEndOfStream, _skipped; } - (instancetype)of_initWithStream: (OFStream *)stream @@ -331,11 +331,11 @@ if (_stream.atEndOfStream && !_decompressedStream.hasDataInReadBuffer) @throw [OFTruncatedDataException exception]; if (length > _toRead) - length = _toRead; + length = (size_t)_toRead; ret = [_decompressedStream readIntoBuffer: buffer length: length]; _toRead -= ret; _CRC16 = OFCRC16(_CRC16, buffer, ret); @@ -371,11 +371,11 @@ } - (void)of_skip { OFStream *stream; - uint32_t toRead; + unsigned long long toRead; if (_stream == nil || _skipped) return; stream = _stream; @@ -396,22 +396,23 @@ stream = _stream; } if ([stream isKindOfClass: [OFSeekableStream class]] && - (sizeof(OFFileOffset) > 4 || toRead < INT32_MAX)) + (sizeof(OFFileOffset) > 4 || toRead != (OFFileOffset)toRead)) [(OFSeekableStream *)stream seekToOffset: (OFFileOffset)toRead whence: SEEK_CUR]; else { while (toRead > 0) { char buffer[512]; - size_t min = toRead; + unsigned long long min = toRead; if (min > 512) min = 512; - toRead -= [stream readIntoBuffer: buffer length: min]; + toRead -= [stream readIntoBuffer: buffer + length: (size_t)min]; } } _toRead = 0; _skipped = true; Index: src/OFLHAArchiveEntry.h ================================================================== --- src/OFLHAArchiveEntry.h +++ src/OFLHAArchiveEntry.h @@ -30,11 +30,11 @@ * @brief A class which represents an entry in an LHA archive. */ @interface OFLHAArchiveEntry: OFObject { OFString *_fileName, *_Nullable _directoryName, *_compressionMethod; - uint32_t _compressedSize, _uncompressedSize; + unsigned long long _compressedSize, _uncompressedSize; OFDate *_modificationDate; uint8_t _headerLevel; uint16_t _CRC16; uint8_t _operatingSystemIdentifier; OFString *_Nullable _fileComment; @@ -55,16 +55,16 @@ @property (readonly, copy, nonatomic) OFString *compressionMethod; /** * @brief The compressed size of the entry's file. */ -@property (readonly, nonatomic) uint32_t compressedSize; +@property (readonly, nonatomic) unsigned long long compressedSize; /** * @brief The uncompressed size of the entry's file. */ -@property (readonly, nonatomic) uint32_t uncompressedSize; +@property (readonly, nonatomic) unsigned long long uncompressedSize; /** * @brief The modification date of the file. */ @property (readonly, retain, nonatomic) OFDate *modificationDate; Index: src/OFLHAArchiveEntry.m ================================================================== --- src/OFLHAArchiveEntry.m +++ src/OFLHAArchiveEntry.m @@ -335,15 +335,21 @@ _compressionMethod = [[OFString alloc] initWithCString: header + 2 encoding: OFStringEncodingASCII length: 5]; + if (_compressedSize > UINT32_MAX || + _uncompressedSize > UINT32_MAX) + @throw [OFOutOfRangeException exception]; + memcpy(&_compressedSize, header + 7, 4); - _compressedSize = OFFromLittleEndian32(_compressedSize); + _compressedSize = + OFFromLittleEndian32((uint32_t)_compressedSize); memcpy(&_uncompressedSize, header + 11, 4); - _uncompressedSize = OFFromLittleEndian32(_uncompressedSize); + _uncompressedSize = + OFFromLittleEndian32((uint32_t)_uncompressedSize); memcpy(&date, header + 15, 4); date = OFFromLittleEndian32(date); _headerLevel = header[20]; @@ -473,16 +479,16 @@ - (OFString *)compressionMethod { return _compressionMethod; } -- (uint32_t)compressedSize +- (unsigned long long)compressedSize { return _compressedSize; } -- (uint32_t)uncompressedSize +- (unsigned long long)uncompressedSize { return _uncompressedSize; } - (OFDate *)modificationDate @@ -557,24 +563,25 @@ getFileNameAndDirectoryName(self, encoding, &fileName, &fileNameLength, &directoryName, &directoryNameLength); if (fileNameLength > UINT16_MAX - 3 || - directoryNameLength > UINT16_MAX - 3) + directoryNameLength > UINT16_MAX - 3 || + _compressedSize > UINT32_MAX || _uncompressedSize > UINT32_MAX) @throw [OFOutOfRangeException exception]; /* Length. Filled in after we're done. */ [data increaseCountBy: 2]; [data addItems: [_compressionMethod cStringWithEncoding: OFStringEncodingASCII] count: 5]; - tmp32 = OFToLittleEndian32(_compressedSize); + tmp32 = OFToLittleEndian32((uint32_t)_compressedSize); [data addItems: &tmp32 count: sizeof(tmp32)]; - tmp32 = OFToLittleEndian32(_uncompressedSize); + tmp32 = OFToLittleEndian32((uint32_t)_uncompressedSize); [data addItems: &tmp32 count: sizeof(tmp32)]; tmp32 = OFToLittleEndian32( (uint32_t)_modificationDate.timeIntervalSince1970); [data addItems: &tmp32 count: sizeof(tmp32)]; @@ -721,12 +728,12 @@ withString: @"\n\t"]; OFString *ret = [OFString stringWithFormat: @"<%@:\n" @"\tFile name = %@\n" @"\tCompression method = %@\n" - @"\tCompressed size = %" @PRIu32 "\n" - @"\tUncompressed size = %" @PRIu32 "\n" + @"\tCompressed size = %llu\n" + @"\tUncompressed size = %llu\n" @"\tModification date = %@\n" @"\tHeader level = %u\n" @"\tCRC16 = %04" @PRIX16 @"\n" @"\tOperating system identifier = %c\n" @"\tComment = %@\n" Index: src/OFMutableLHAArchiveEntry.h ================================================================== --- src/OFMutableLHAArchiveEntry.h +++ src/OFMutableLHAArchiveEntry.h @@ -39,16 +39,16 @@ @property (readwrite, copy, nonatomic) OFString *compressionMethod; /** * @brief The compressed size of the entry's file. */ -@property (readwrite, nonatomic) uint32_t compressedSize; +@property (readwrite, nonatomic) unsigned long long compressedSize; /** * @brief The uncompressed size of the entry's file. */ -@property (readwrite, nonatomic) uint32_t uncompressedSize; +@property (readwrite, nonatomic) unsigned long long uncompressedSize; /** * @brief The modification date of the file. */ @property (readwrite, retain, nonatomic) OFDate *modificationDate; Index: src/OFMutableLHAArchiveEntry.m ================================================================== --- src/OFMutableLHAArchiveEntry.m +++ src/OFMutableLHAArchiveEntry.m @@ -72,16 +72,16 @@ OFString *old = _compressionMethod; _compressionMethod = [compressionMethod copy]; [old release]; } -- (void)setCompressedSize: (uint32_t)compressedSize +- (void)setCompressedSize: (unsigned long long)compressedSize { _compressedSize = compressedSize; } -- (void)setUncompressedSize: (uint32_t)uncompressedSize +- (void)setUncompressedSize: (unsigned long long)uncompressedSize { _uncompressedSize = uncompressedSize; } - (void)setModificationDate: (OFDate *)modificationDate Index: utils/ofarc/LHAArchive.m ================================================================== --- utils/ofarc/LHAArchive.m +++ utils/ofarc/LHAArchive.m @@ -121,13 +121,13 @@ if (app->_outputLevel >= 1) { OFString *modificationDate = [entry.modificationDate localDateStringWithFormat: @"%Y-%m-%d %H:%M:%S"]; OFString *compressedSize = [OFString stringWithFormat: - @"%" PRIu32, entry.compressedSize]; + @"%llu", entry.compressedSize]; OFString *uncompressedSize = [OFString stringWithFormat: - @"%" PRIu32, entry.uncompressedSize]; + @"%llu", entry.uncompressedSize]; OFString *CRC16 = [OFString stringWithFormat: @"%04" PRIX16, entry.CRC16]; [OFStdOut writeString: @"\t"]; [OFStdOut writeLine: OF_LOCALIZED( @@ -256,11 +256,11 @@ void *pool = objc_autoreleasePoolPush(); OFString *fileName = entry.fileName; OFString *outFileName, *directory; OFFile *output; OFStream *stream; - 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;