ObjFW  Check-in [f91dbd8975]

Overview
Comment:OFDeflateStream: Minor improvements.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: f91dbd897546cdbc4db86647829fd377364f4e0c8c67377d7736195d59066f31
User & Date: js on 2013-10-29 10:09:19
Other Links: manifest | tags
Context
2013-10-29
18:00
OFZIPArchive: Only check lower byte of minVersion. check-in: 1ce5d53f93 user: js tags: trunk
10:09
OFDeflateStream: Minor improvements. check-in: f91dbd8975 user: js tags: trunk
09:55
OFZIPArchiveEntry: More elaborate -[description]. check-in: 7d10ec24b0 user: js tags: trunk
Changes

Modified src/OFDeflateStream.m from [d790744286] to [b262daf9b1].

420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
	case HUFFMAN_TREE:
#define CTX _context.huffmanTree
		if OF_LIKELY (CTX.value == 0xFE) {
			if OF_LIKELY (CTX.litLenCodesCount == 0xFF) {
				if OF_UNLIKELY (!tryReadBits(self, &bits, 5))
					return bytesWritten;

				if OF_UNLIKELY (bits > 30)
					@throw [OFInvalidFormatException
					    exception];

				CTX.litLenCodesCount = bits;
			}

			if OF_LIKELY (CTX.distCodesCount == 0xFF) {
				if OF_UNLIKELY (!tryReadBits(self, &bits, 5))
					return bytesWritten;

				CTX.distCodesCount = bits;
			}

			if OF_LIKELY (CTX.codeLenCodesCount == 0xFF) {
				if OF_UNLIKELY (!tryReadBits(self, &bits, 4))
					return bytesWritten;

				if OF_UNLIKELY (bits + 4 > 19)
					@throw [OFInvalidFormatException
					    exception];

				CTX.codeLenCodesCount = bits;
			}

			if OF_LIKELY (CTX.lengths == NULL) {
				CTX.lengths = [self allocMemoryWithSize: 19];
				memset(CTX.lengths, 0, 19);
			}







|

















<
<
<
<







420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444




445
446
447
448
449
450
451
	case HUFFMAN_TREE:
#define CTX _context.huffmanTree
		if OF_LIKELY (CTX.value == 0xFE) {
			if OF_LIKELY (CTX.litLenCodesCount == 0xFF) {
				if OF_UNLIKELY (!tryReadBits(self, &bits, 5))
					return bytesWritten;

				if OF_UNLIKELY (bits > 29)
					@throw [OFInvalidFormatException
					    exception];

				CTX.litLenCodesCount = bits;
			}

			if OF_LIKELY (CTX.distCodesCount == 0xFF) {
				if OF_UNLIKELY (!tryReadBits(self, &bits, 5))
					return bytesWritten;

				CTX.distCodesCount = bits;
			}

			if OF_LIKELY (CTX.codeLenCodesCount == 0xFF) {
				if OF_UNLIKELY (!tryReadBits(self, &bits, 4))
					return bytesWritten;





				CTX.codeLenCodesCount = bits;
			}

			if OF_LIKELY (CTX.lengths == NULL) {
				CTX.lengths = [self allocMemoryWithSize: 19];
				memset(CTX.lengths, 0, 19);
			}
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
		}

		if OF_LIKELY (CTX.lengths == NULL)
			CTX.lengths = [self allocMemoryWithSize:
			    CTX.litLenCodesCount + CTX.distCodesCount + 258];

		for (i = CTX.receivedCount;
		    i < CTX.litLenCodesCount + CTX.distCodesCount + 258; i++) {
			uint_fast8_t j, count;

			if OF_LIKELY (CTX.value == 0xFF) {
				if OF_UNLIKELY (!walkTree(self, &CTX.treeIter,
				    &value)) {
					CTX.receivedCount = i;
					return bytesWritten;
				}

				CTX.treeIter = CTX.codeLenTree;

				if (value < 16) {
					CTX.lengths[i] = value;
					continue;
				}
			} else
				value = CTX.value;

			switch (value) {
			case 16:







|












|







470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
		}

		if OF_LIKELY (CTX.lengths == NULL)
			CTX.lengths = [self allocMemoryWithSize:
			    CTX.litLenCodesCount + CTX.distCodesCount + 258];

		for (i = CTX.receivedCount;
		    i < CTX.litLenCodesCount + CTX.distCodesCount + 258;) {
			uint_fast8_t j, count;

			if OF_LIKELY (CTX.value == 0xFF) {
				if OF_UNLIKELY (!walkTree(self, &CTX.treeIter,
				    &value)) {
					CTX.receivedCount = i;
					return bytesWritten;
				}

				CTX.treeIter = CTX.codeLenTree;

				if (value < 16) {
					CTX.lengths[i++] = value;
					continue;
				}
			} else
				value = CTX.value;

			switch (value) {
			case 16:
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555

			if OF_UNLIKELY (i + count >
			    CTX.litLenCodesCount + CTX.distCodesCount + 258)
				@throw [OFInvalidFormatException exception];

			for (j = 0; j < count; j++)
				CTX.lengths[i++] = value;
			i--;

			CTX.value = 0xFF;
		}

		releaseTree(CTX.codeLenTree);

		CTX.litLenTree = constructTree(CTX.lengths,







<







537
538
539
540
541
542
543

544
545
546
547
548
549
550

			if OF_UNLIKELY (i + count >
			    CTX.litLenCodesCount + CTX.distCodesCount + 258)
				@throw [OFInvalidFormatException exception];

			for (j = 0; j < count; j++)
				CTX.lengths[i++] = value;


			CTX.value = 0xFF;
		}

		releaseTree(CTX.codeLenTree);

		CTX.litLenTree = constructTree(CTX.lengths,
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
					_slidingWindow = [self
					    allocMemoryWithSize: 0x8000];
					/* Avoid leaking data */
					memset(_slidingWindow, 0, 0x8000);
				}

				_slidingWindow[_slidingWindowIndex] = CTX.value;
				_slidingWindowIndex = (_slidingWindowIndex +
				    1) & 0x7FFF;

				CTX.state = AWAIT_CODE;
				CTX.treeIter = CTX.litLenTree;
			}

			if OF_UNLIKELY (CTX.state == AWAIT_LENGTH_EXTRA_BITS) {
				if OF_UNLIKELY (!tryReadBits(self, &bits,







|
|







582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
					_slidingWindow = [self
					    allocMemoryWithSize: 0x8000];
					/* Avoid leaking data */
					memset(_slidingWindow, 0, 0x8000);
				}

				_slidingWindow[_slidingWindowIndex] = CTX.value;
				_slidingWindowIndex =
				    (_slidingWindowIndex + 1) & 0x7FFF;

				CTX.state = AWAIT_CODE;
				CTX.treeIter = CTX.litLenTree;
			}

			if OF_UNLIKELY (CTX.state == AWAIT_LENGTH_EXTRA_BITS) {
				if OF_UNLIKELY (!tryReadBits(self, &bits,
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
					_slidingWindow = [self
					    allocMemoryWithSize: 0x8000];
					/* Avoid leaking data */
					memset(_slidingWindow, 0, 0x8000);
				}

				_slidingWindow[_slidingWindowIndex] = value;
				_slidingWindowIndex = (_slidingWindowIndex +
				    1) & 0x7FFF;

				CTX.treeIter = CTX.litLenTree;
				continue;
			}

			if OF_UNLIKELY (value > 285)
				@throw [OFInvalidFormatException exception];







|
|







702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
					_slidingWindow = [self
					    allocMemoryWithSize: 0x8000];
					/* Avoid leaking data */
					memset(_slidingWindow, 0, 0x8000);
				}

				_slidingWindow[_slidingWindowIndex] = value;
				_slidingWindowIndex =
				    (_slidingWindowIndex + 1) & 0x7FFF;

				CTX.treeIter = CTX.litLenTree;
				continue;
			}

			if OF_UNLIKELY (value > 285)
				@throw [OFInvalidFormatException exception];