Overview
Comment: | Rename OFChecksum{Failed -> Mismatch}Exception
This also adds a parameter for the actual and expected checksum. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
8f21e8acb521e0f3b2b1a4a25fea893f |
User & Date: | js on 2018-06-12 21:33:18 |
Other Links: | manifest | tags |
Context
2018-06-16
| ||
14:15 | Wrap a few @public in #ifdefs check-in: 7d86d2dd2b user: js tags: trunk | |
2018-06-12
| ||
21:33 | Rename OFChecksum{Failed -> Mismatch}Exception check-in: 8f21e8acb5 user: js tags: trunk | |
2018-06-10
| ||
20:29 | OF{LHA,ZIP}Archive: Improve truncation detection check-in: 6b42e44f99 user: js tags: trunk | |
Changes
Modified src/OFGZIPStream.m from [366b9ff49d] to [2759f9564f].
︙ | ︙ | |||
19 20 21 22 23 24 25 | #import "OFGZIPStream.h" #import "OFInflateStream.h" #import "OFDate.h" #import "crc32.h" | | | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #import "OFGZIPStream.h" #import "OFInflateStream.h" #import "OFDate.h" #import "crc32.h" #import "OFChecksumMismatchException.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" #import "OFNotOpenException.h" #import "OFTruncatedDataException.h" @implementation OFGZIPStream + (instancetype)streamWithStream: (OFStream *)stream |
︙ | ︙ | |||
77 78 79 80 81 82 83 84 85 86 87 88 89 90 | length: (size_t)length { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; for (;;) { uint8_t byte; if ([_stream isAtEndOfStream]) { if (_state != OF_GZIP_STREAM_ID1) @throw [OFTruncatedDataException exception]; return 0; } | > | 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | length: (size_t)length { if (_stream == nil) @throw [OFNotOpenException exceptionWithObject: self]; for (;;) { uint8_t byte; uint32_t CRC32, uncompressedSize; if ([_stream isAtEndOfStream]) { if (_state != OF_GZIP_STREAM_ID1) @throw [OFTruncatedDataException exception]; return 0; } |
︙ | ︙ | |||
257 258 259 260 261 262 263 | case OF_GZIP_STREAM_CRC32: _bytesRead += [_stream readIntoBuffer: _buffer length: 4 - _bytesRead]; if (_bytesRead < 4) return 0; | | | > > > > > > | > > > | | > > | > > > | > > > | 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | case OF_GZIP_STREAM_CRC32: _bytesRead += [_stream readIntoBuffer: _buffer length: 4 - _bytesRead]; if (_bytesRead < 4) return 0; CRC32 = ((uint32_t)_buffer[3] << 24) | (_buffer[2] << 16) | (_buffer[1] << 8) | _buffer[0]; if (~_CRC32 != CRC32) { OFString *actual = [OFString stringWithFormat: @"%08" PRIX32, ~_CRC32]; OFString *expected = [OFString stringWithFormat: @"%08" PRIX32, CRC32]; @throw [OFChecksumMismatchException exceptionWithActualChecksum: actual expectedChecksum: expected]; } _bytesRead = 0; _CRC32 = ~0; _state++; break; case OF_GZIP_STREAM_UNCOMPRESSED_SIZE: _bytesRead += [_stream readIntoBuffer: _buffer length: 4 - _bytesRead]; uncompressedSize = ((uint32_t)_buffer[3] << 24) | (_buffer[2] << 16) | (_buffer[1] << 8) | _buffer[0]; if (_uncompressedSize != uncompressedSize) { OFString *actual = [OFString stringWithFormat: @"%" PRIu32, _uncompressedSize]; OFString *expected = [OFString stringWithFormat: @"%" PRIu32, uncompressedSize]; @throw [OFChecksumMismatchException exceptionWithActualChecksum: actual expectedChecksum: expected]; } _bytesRead = 0; _uncompressedSize = 0; _state = OF_GZIP_STREAM_ID1; break; } } |
︙ | ︙ |
Modified src/OFLHAArchive.m from [4f0d23572a] to [1f3aa621cb].
︙ | ︙ | |||
28 29 30 31 32 33 34 | #import "OFStream.h" #import "OFSeekableStream.h" #import "OFString.h" #import "crc16.h" #import "huffman_tree.h" | | | 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | #import "OFStream.h" #import "OFSeekableStream.h" #import "OFString.h" #import "crc16.h" #import "huffman_tree.h" #import "OFChecksumMismatchException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" #import "OFNotOpenException.h" #import "OFTruncatedDataException.h" #define LHSTREAM_BUFFER_SIZE 4096 |
︙ | ︙ | |||
806 807 808 809 810 811 812 | _toRead -= ret; _CRC16 = of_crc16(_CRC16, buffer, ret); if (_toRead == 0) { _atEndOfStream = true; | | > > > > > | > > > | 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 | _toRead -= ret; _CRC16 = of_crc16(_CRC16, buffer, ret); if (_toRead == 0) { _atEndOfStream = true; if (_CRC16 != [_entry CRC16]) { OFString *actualChecksum = [OFString stringWithFormat: @"%04" PRIX16, _CRC16]; OFString *expectedChecksum = [OFString stringWithFormat: @"%04" PRIX16, [_entry CRC16]]; @throw [OFChecksumMismatchException exceptionWithActualChecksum: actualChecksum expectedChecksum: expectedChecksum]; } } return ret; } - (bool)hasDataInReadBuffer { |
︙ | ︙ |
Modified src/OFZIPArchive.m from [0463ac5206] to [9e27ae6fff].
︙ | ︙ | |||
31 32 33 34 35 36 37 | # import "OFFile.h" #endif #import "OFInflateStream.h" #import "OFInflate64Stream.h" #import "crc32.h" | | | 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | # import "OFFile.h" #endif #import "OFInflateStream.h" #import "OFInflate64Stream.h" #import "crc32.h" #import "OFChecksumMismatchException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" #import "OFNotOpenException.h" #import "OFOpenItemFailedException.h" #import "OFOutOfRangeException.h" #import "OFSeekFailedException.h" |
︙ | ︙ | |||
814 815 816 817 818 819 820 | _toRead -= ret; _CRC32 = of_crc32(_CRC32, buffer, ret); if (_toRead == 0) { _atEndOfStream = true; | | > > > > > | > > > | 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 | _toRead -= ret; _CRC32 = of_crc32(_CRC32, buffer, ret); if (_toRead == 0) { _atEndOfStream = true; if (~_CRC32 != [_entry CRC32]) { OFString *actualChecksum = [OFString stringWithFormat: @"%08" PRIX32, ~_CRC32]; OFString *expectedChecksum = [OFString stringWithFormat: @"%08" PRIX32, [_entry CRC32]]; @throw [OFChecksumMismatchException exceptionWithActualChecksum: actualChecksum expectedChecksum: expectedChecksum]; } } return ret; } - (bool)hasDataInReadBuffer { |
︙ | ︙ |
Modified src/ObjFW.h from [5b600283bc] to [d8f06920eb].
︙ | ︙ | |||
128 129 130 131 132 133 134 | #ifdef OF_HAVE_SOCKETS # import "OFAcceptFailedException.h" # import "OFAddressTranslationFailedException.h" # import "OFAlreadyConnectedException.h" # import "OFBindFailedException.h" #endif #import "OFChangeCurrentDirectoryPathFailedException.h" | | | 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | #ifdef OF_HAVE_SOCKETS # import "OFAcceptFailedException.h" # import "OFAddressTranslationFailedException.h" # import "OFAlreadyConnectedException.h" # import "OFBindFailedException.h" #endif #import "OFChangeCurrentDirectoryPathFailedException.h" #import "OFChecksumMismatchException.h" #ifdef OF_HAVE_THREADS # import "OFConditionBroadcastFailedException.h" # import "OFConditionSignalFailedException.h" # import "OFConditionStillWaitingException.h" # import "OFConditionWaitFailedException.h" #endif #ifdef OF_HAVE_SOCKETS |
︙ | ︙ |
Modified src/exceptions/Makefile from [667f570482] to [dcb34a8da1].
1 2 3 4 5 6 7 | include ../../extra.mk STATIC_PIC_LIB_NOINST = ${EXCEPTIONS_LIB_A} STATIC_LIB_NOINST = ${EXCEPTIONS_A} SRCS = OFAllocFailedException.m \ OFChangeCurrentDirectoryPathFailedException.m \ | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | include ../../extra.mk STATIC_PIC_LIB_NOINST = ${EXCEPTIONS_LIB_A} STATIC_LIB_NOINST = ${EXCEPTIONS_A} SRCS = OFAllocFailedException.m \ OFChangeCurrentDirectoryPathFailedException.m \ OFChecksumMismatchException.m \ OFCopyItemFailedException.m \ OFCreateDirectoryFailedException.m \ OFCreateSymbolicLinkFailedException.m \ OFEnumerationMutationException.m \ OFException.m \ OFGetOptionFailedException.m \ OFHashAlreadyCalculatedException.m \ |
︙ | ︙ |
Deleted src/exceptions/OFChecksumFailedException.h version [4c03396bff].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Deleted src/exceptions/OFChecksumFailedException.m version [e5945cfdb9].
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Added src/exceptions/OFChecksumMismatchException.h version [9576163f70].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | /* * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, * 2018 * Jonathan Schleifer <js@heap.zone> * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in * the packaging of this file. * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFException.h" OF_ASSUME_NONNULL_BEGIN /*! * @class OFChecksumMismatchException \ * OFChecksumMismatchException.h ObjFW/OFChecksumMismatchException.h * * @brief An exception indicating that a checksum did not match. */ @interface OFChecksumMismatchException: OFException { OFString *_actualChecksum, *_expectedChecksum; } /*! * @brief The actual checksum calculated. */ @property (readonly, nonatomic) OFString *actualChecksum; /*! * @brief The expected checksum. */ @property (readonly, nonatomic) OFString *expectedChecksum; + (instancetype)exception OF_UNAVAILABLE; /*! * @brief Creates a new, autoreleased checksum mismatch exception. * * @param actualChecksum The actual checksum calculated * @param expectedChecksum The expected checksum * @return A new, autoreleased checksum mismatch exception. */ + (instancetype)exceptionWithActualChecksum: (OFString *)actualChecksum expectedChecksum: (OFString *)expectedChecksum; - (instancetype)init OF_UNAVAILABLE; /*! * @brief Initializes an already allocated checksum mismatch exception. * * @param actualChecksum The actual checksum calculated * @param expectedChecksum The expected checksum * @return An initialized checksum mismatch exception. */ - (instancetype)initWithActualChecksum: (OFString *)actualChecksum expectedChecksum: (OFString *)expectedChecksum OF_DESIGNATED_INITIALIZER; @end OF_ASSUME_NONNULL_END |
Added src/exceptions/OFChecksumMismatchException.m version [77d7bc3f8d].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | /* * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, * 2018 * Jonathan Schleifer <js@heap.zone> * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in * the packaging of this file. * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #import "OFChecksumMismatchException.h" #import "OFString.h" @implementation OFChecksumMismatchException @synthesize actualChecksum = _actualChecksum; @synthesize expectedChecksum = _expectedChecksum; + (instancetype)exception { OF_UNRECOGNIZED_SELECTOR } + (instancetype)exceptionWithActualChecksum: (OFString *)actualChecksum expectedChecksum: (OFString *)expectedChecksum { return [[[self alloc] initWithActualChecksum: actualChecksum expectedChecksum: expectedChecksum] autorelease]; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (instancetype)initWithActualChecksum: (OFString *)actualChecksum expectedChecksum: (OFString *)expectedChecksum { self = [super init]; @try { _actualChecksum = [actualChecksum copy]; _expectedChecksum = [expectedChecksum copy]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_actualChecksum release]; [_expectedChecksum release]; [super dealloc]; } - (OFString *)description { return [OFString stringWithFormat: @"Checksum was %@ but %@ was expected!", _actualChecksum, _expectedChecksum]; } @end |