| 653 | } |
| 654 | |
| 655 | void Inflator_inflate(VECTOR_8 *out, const VECTOR_8 *in, UINT32 inpos) |
| 656 | { |
| 657 | UINT32 bp = 0, pos = 0; // bit pointer and byte pointer |
| 658 | UINT32 BFINAL = 0; |
| 659 | UINT32 BTYPE; |
| 660 | Inflator_error = 0; |
| 661 | while (!BFINAL && !Inflator_error) { |
| 662 | if (bp >> 3 >= in->size) { |
| 663 | Inflator_error = 52; // error, bit pointer will jump past memory |
| 664 | return; |
| 665 | } |
| 666 | BFINAL = Zlib_readBitFromStream(&bp, &in->data[inpos]); |
| 667 | BTYPE = Zlib_readBitFromStream(&bp, &in->data[inpos]); |
| 668 | BTYPE += 2 * Zlib_readBitFromStream(&bp, &in->data[inpos]); |
| 669 | if (BTYPE == 3) |
| 670 | { |
| 671 | Inflator_error = 20; // error: invalid BTYPE |
| 672 | return; |
| 673 | } |
| 674 | else if (BTYPE == 0) |
| 675 | Inflator_inflateNoCompression(out, &in->data[inpos], &bp, &pos, in->size); |
| 676 | else |
| 677 | Inflator_inflateHuffmanBlock(out, &in->data[inpos], &bp, &pos, in->size, BTYPE); |
| 678 | } |
| 679 | if (!Inflator_error) |
| 680 | vector8_resize(out, pos); // Only now we know the TRUE size of out, resize it to that |
| 681 | } |
| 682 | |
| 683 | /*************************************************************************************************/ |
| 684 |
no test coverage detected