Differences From Artifact [366b9ff49d]:
- File src/OFGZIPStream.m — part of check-in [7e5c81e186] at 2018-01-03 19:49:46 on branch trunk — Update copyright notice (user: js, size: 6649) [annotate] [blame] [check-ins using]
To Artifact [2759f9564f]:
- File
src/OFGZIPStream.m
— part of check-in
[8f21e8acb5]
at
2018-06-12 21:33:18
on branch trunk
— Rename OFChecksum{Failed -> Mismatch}Exception
This also adds a parameter for the actual and expected checksum. (user: js, size: 7253) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
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; } } |
︙ | ︙ |