Overview
Comment: | OFLHAArchive: Verify CRC16 checksum |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
fca5e53e12d5fd6090ed577edcf34f94 |
User & Date: | js on 2018-06-04 22:05:20 |
Other Links: | manifest | tags |
Context
2018-06-04
| ||
22:47 | OFLHAArchive: Prefill the sliding window with ' ' check-in: 744956a000 user: js tags: trunk | |
22:05 | OFLHAArchive: Verify CRC16 checksum check-in: fca5e53e12 user: js tags: trunk | |
2018-06-03
| ||
23:31 | Add -[OFObject allocZeroedMemoryWithSize:(count:)] check-in: aacb5897a0 user: js tags: trunk | |
Changes
Modified src/Makefile from [a713f01f52] to [66da2ef2a8].
︙ | ︙ | |||
104 105 106 107 108 109 110 111 112 113 114 115 116 117 | OFXMLElementBuilder.m \ OFXMLNode.m \ OFXMLParser.m \ OFXMLProcessingInstructions.m \ OFZIPArchive.m \ OFZIPArchiveEntry.m \ base64.m \ crc32.m \ huffman_tree.m \ of_asprintf.m \ of_strptime.m \ pbkdf2.m \ scrypt.m \ ${UNICODE_M} \ | > | 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | OFXMLElementBuilder.m \ OFXMLNode.m \ OFXMLParser.m \ OFXMLProcessingInstructions.m \ OFZIPArchive.m \ OFZIPArchiveEntry.m \ base64.m \ crc16.m \ crc32.m \ huffman_tree.m \ of_asprintf.m \ of_strptime.m \ pbkdf2.m \ scrypt.m \ ${UNICODE_M} \ |
︙ | ︙ |
Modified src/OFLHAArchive.m from [56fa949e3a] to [6f9fadd6e2].
︙ | ︙ | |||
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | #ifdef OF_HAVE_FILES # import "OFFile.h" #endif #import "OFStream.h" #import "OFSeekableStream.h" #import "OFString.h" #import "huffman_tree.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" #import "OFNotOpenException.h" #import "OFTruncatedDataException.h" #define LHSTREAM_BUFFER_SIZE 4096 | > > | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | #ifdef OF_HAVE_FILES # import "OFFile.h" #endif #import "OFStream.h" #import "OFSeekableStream.h" #import "OFString.h" #import "crc16.h" #import "huffman_tree.h" #import "OFChecksumFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFNotImplementedException.h" #import "OFNotOpenException.h" #import "OFTruncatedDataException.h" #define LHSTREAM_BUFFER_SIZE 4096 |
︙ | ︙ | |||
67 68 69 70 71 72 73 74 75 76 77 78 79 80 | dictionaryBits: (uint8_t)dictionaryBits; @end @interface OFLHAArchive_FileReadStream: OFStream <OFReadyForReadingObserving> { OF_KINDOF(OFStream *) _stream; uint32_t _toRead; bool _atEndOfStream; } - (instancetype)of_initWithStream: (OFStream *)stream entry: (OFLHAArchiveEntry *)entry; - (void)of_skip; @end | > | 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | dictionaryBits: (uint8_t)dictionaryBits; @end @interface OFLHAArchive_FileReadStream: OFStream <OFReadyForReadingObserving> { OF_KINDOF(OFStream *) _stream; uint32_t _toRead; uint16_t _expectedCRC16, _CRC16; bool _atEndOfStream; } - (instancetype)of_initWithStream: (OFStream *)stream entry: (OFLHAArchiveEntry *)entry; - (void)of_skip; @end |
︙ | ︙ | |||
724 725 726 727 728 729 730 731 732 733 734 735 736 737 | if ([method isEqual: @"-lh0-"] || [method isEqual: @"-lhd-"] || [method isEqual: @"-lz4-"] || [method isEqual: @"-lh5-"] || [method isEqual: @"-lh6-"] || [method isEqual: @"-lh6-"]) _toRead = [entry uncompressedSize]; else _toRead = [entry compressedSize]; } @catch (id e) { [self release]; @throw e; } return self; } | > > | 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 | if ([method isEqual: @"-lh0-"] || [method isEqual: @"-lhd-"] || [method isEqual: @"-lz4-"] || [method isEqual: @"-lh5-"] || [method isEqual: @"-lh6-"] || [method isEqual: @"-lh6-"]) _toRead = [entry uncompressedSize]; else _toRead = [entry compressedSize]; _expectedCRC16 = [entry CRC16]; } @catch (id e) { [self release]; @throw e; } return self; } |
︙ | ︙ | |||
757 758 759 760 761 762 763 764 | if (length > _toRead) length = _toRead; ret = [_stream readIntoBuffer: buffer length: length]; _toRead -= ret; | > | > > > > | 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 | if (length > _toRead) length = _toRead; ret = [_stream readIntoBuffer: buffer length: length]; _toRead -= ret; _CRC16 = of_crc16(_CRC16, buffer, ret); if (_toRead == 0) { _atEndOfStream = true; if (_CRC16 != _expectedCRC16) @throw [OFChecksumFailedException exception]; } return ret; } - (bool)lowlevelIsAtEndOfStream { if (_stream == nil) |
︙ | ︙ |
Modified src/ObjFW.h from [42d5f9fcae] to [5b600283bc].
︙ | ︙ | |||
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | # import "OFThreadPool.h" # import "OFMutex.h" # import "OFRecursiveMutex.h" # import "OFCondition.h" #endif #import "base64.h" #import "crc32.h" #import "instance.h" #import "of_asprintf.h" #import "of_strptime.h" #ifdef OF_HAVE_SOCKETS # import "resolver.h" #endif #import "pbkdf2.h" #import "scrypt.h" #import "unicode.h" | > > | 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | # import "OFThreadPool.h" # import "OFMutex.h" # import "OFRecursiveMutex.h" # import "OFCondition.h" #endif #import "base64.h" #import "crc16.h" #import "crc32.h" #import "huffman_tree.h" #import "instance.h" #import "of_asprintf.h" #import "of_strptime.h" #ifdef OF_HAVE_SOCKETS # import "resolver.h" #endif #import "pbkdf2.h" #import "scrypt.h" #import "unicode.h" |
Added src/crc16.h version [602628a08f].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 | /* * 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. */ #ifndef __STDC_LIMIT_MACROS # define __STDC_LIMIT_MACROS #endif #ifndef __STDC_CONSTANT_MACROS # define __STDC_CONSTANT_MACROS #endif #import "macros.h" #ifdef __cplusplus extern "C" { #endif extern uint16_t of_crc16(uint16_t crc, const unsigned char *_Nonnull bytes, size_t length); #ifdef __cplusplus } #endif |
Added src/crc16.m version [19a9c6f1a5].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 | /* * 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 "crc32.h" #define CRC16_MAGIC 0xA001 uint16_t of_crc16(uint16_t crc, const unsigned char *bytes, size_t length) { for (size_t i = 0; i < length; i++) { crc ^= bytes[i]; for (uint8_t j = 0; j < 8; j++) crc = (crc >> 1) ^ (CRC16_MAGIC & (~(crc & 1) + 1)); } return crc; } |