Differences From Artifact [2026ad717c]:
- File src/OFZIPArchive.m — part of check-in [a1ea38be5b] at 2023-07-25 21:35:57 on branch trunk — Make GCC happy again (user: js, size: 27841) [annotate] [blame] [check-ins using]
To Artifact [03f366c882]:
- File
src/OFZIPArchive.m
— part of check-in
[a847357585]
at
2023-07-26 19:05:36
on branch trunk
— OFZIPArchive: Handle CD spanning multiple parts
Unfortunately, I could not find a file to test this with, as this is an
extremely rare corner case that basically doesn't seem to exist with
real world files: It requires an extremely small part size for an
archive with thousands of files. (user: js, size: 28748) [annotate] [blame] [check-ins using] [more...]
︙ | ︙ | |||
43 44 45 46 47 48 49 | #import "OFOutOfRangeException.h" #import "OFSeekFailedException.h" #import "OFTruncatedDataException.h" #import "OFUnsupportedVersionException.h" #import "OFWriteFailedException.h" /* | | < | 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | #import "OFOutOfRangeException.h" #import "OFSeekFailedException.h" #import "OFTruncatedDataException.h" #import "OFUnsupportedVersionException.h" #import "OFWriteFailedException.h" /* * TODO: Current limitations: * - Encrypted files cannot be read. */ enum { modeRead, modeWrite, modeAppend |
︙ | ︙ | |||
155 156 157 158 159 160 161 | @synthesize delegate = _delegate, archiveComment = _archiveComment; static void seekOrThrowInvalidFormat(OFZIPArchive *archive, const uint32_t *diskNumber, OFStreamOffset offset, OFSeekWhence whence) { if (diskNumber != NULL && *diskNumber != archive->_diskNumber) { | | < | 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | @synthesize delegate = _delegate, archiveComment = _archiveComment; static void seekOrThrowInvalidFormat(OFZIPArchive *archive, const uint32_t *diskNumber, OFStreamOffset offset, OFSeekWhence whence) { if (diskNumber != NULL && *diskNumber != archive->_diskNumber) { OFStream *oldStream = archive->_stream; OFSeekableStream *stream; if (archive->_mode != modeRead || *diskNumber > archive->_lastDiskNumber) @throw [OFInvalidFormatException exception]; stream = [archive->_delegate archive: archive wantsPartNumbered: *diskNumber lastPartNumber: archive->_lastDiskNumber]; if (stream == nil) @throw [OFInvalidFormatException exception]; |
︙ | ︙ | |||
395 396 397 398 399 400 401 | (OFStreamOffset)_centralDirectoryOffset != _centralDirectoryOffset) @throw [OFOutOfRangeException exception]; seekOrThrowInvalidFormat(self, &_centralDirectoryDisk, (OFStreamOffset)_centralDirectoryOffset, OFSeekSet); for (size_t i = 0; i < _centralDirectoryEntries; i++) { | | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 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 | (OFStreamOffset)_centralDirectoryOffset != _centralDirectoryOffset) @throw [OFOutOfRangeException exception]; seekOrThrowInvalidFormat(self, &_centralDirectoryDisk, (OFStreamOffset)_centralDirectoryOffset, OFSeekSet); for (size_t i = 0; i < _centralDirectoryEntries; i++) { OFZIPArchiveEntry *entry; char buffer; /* * The stream might have 0 bytes left to read, but might not * realize that before a read is attempted, where it will then * return a length of 0. But OFZIPArchiveEntry expects to be * able to read the entire entry and will then throw an * OFTruncatedDataException. Therefore, try to peek one byte to * make sure the stream realizes that it's at the end. */ if ([_stream readIntoBuffer: &buffer length: 1] == 1) [_stream unreadFromBuffer: &buffer length: 1]; if ([_stream isAtEndOfStream]) { OFStream *oldStream = _stream; OFSeekableStream *stream; if (_diskNumber >= _lastDiskNumber) @throw [OFTruncatedDataException exception]; stream = [_delegate archive: self wantsPartNumbered: _diskNumber + 1 lastPartNumber: _lastDiskNumber]; if (stream == nil) @throw [OFInvalidFormatException exception]; _diskNumber++; _stream = [stream retain]; [oldStream release]; } entry = [[[OFZIPArchiveEntry alloc] of_initWithStream: _stream] autorelease]; if ([_pathToEntryMap objectForKey: entry.fileName] != nil) @throw [OFInvalidFormatException exception]; [_entries addObject: entry]; [_pathToEntryMap setObject: entry forKey: entry.fileName]; |
︙ | ︙ | |||
839 840 841 842 843 844 845 | @throw [OFNotOpenException exceptionWithObject: self]; if (_atEndOfStream) return 0; if ([_archive->_stream isAtEndOfStream] && ![_decompressedStream hasDataInReadBuffer]) { | | < | 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 | @throw [OFNotOpenException exceptionWithObject: self]; if (_atEndOfStream) return 0; if ([_archive->_stream isAtEndOfStream] && ![_decompressedStream hasDataInReadBuffer]) { OFStream *oldStream = _archive->_stream, *oldDecompressedStream; OFSeekableStream *stream; if (_archive->_diskNumber >= _archive->_lastDiskNumber) @throw [OFTruncatedDataException exception]; stream = [_archive->_delegate archive: _archive wantsPartNumbered: _archive->_diskNumber + 1 lastPartNumber: _archive->_lastDiskNumber]; if (stream == nil) @throw [OFInvalidFormatException exception]; |
︙ | ︙ |