Exemple #1
0
        internal static int InflateTreeDynamic(
            int nl,
            int nd,
            int[] c,
            int[] bl,
            int[] bd,
            int[] tl,
            int[] td,
            int[] hp,
            CompressionStream z)
        {
            int[] v    = new int[288];
            int[] hn   = new int[1];
            int   num1 = InflaterTree.BuildHuffmanTree(c, 0, nl, 257, InflaterTreeConstants.CpLens, InflaterTreeConstants.CpLext, tl, bl, hp, hn, v);

            if (num1 != 0 || bl[0] == 0)
            {
                switch (num1)
                {
                case -4:
                    return(num1);

                case -3:
                    z.ErrorMessage = "oversubscribed literal/length tree";
                    goto case -4;

                default:
                    z.ErrorMessage = "incomplete literal/length tree";
                    num1           = -3;
                    goto case -4;
                }
            }
            else
            {
                int num2 = InflaterTree.BuildHuffmanTree(c, nl, nd, 0, InflaterTreeConstants.CpDist, InflaterTreeConstants.CpDext, td, bd, hp, hn, v);
                if (num2 == 0 && (bd[0] != 0 || nl <= 257))
                {
                    return(0);
                }
                switch (num2)
                {
                case -5:
                    z.ErrorMessage = "incomplete distance tree";
                    num2           = -3;
                    goto case -4;

                case -4:
                    return(num2);

                case -3:
                    z.ErrorMessage = "oversubscribed distance tree";
                    goto case -4;

                default:
                    z.ErrorMessage = "empty distance tree with lengths";
                    num2           = -3;
                    goto case -4;
                }
            }
        }
Exemple #2
0
        internal static int InflateTreeBits(
            int[] c,
            int[] bb,
            int[] tb,
            int[] hp,
            CompressionStream z)
        {
            int[] hn   = new int[1];
            int[] v    = new int[19];
            int   num1 = InflaterTree.BuildHuffmanTree(c, 0, 19, 19, (int[])null, (int[])null, tb, bb, hp, hn, v);
            int   num2;

            switch (num1)
            {
            case -5:
                num2 = 0;
                break;

            case -3:
                z.ErrorMessage = "oversubscribed dynamic bit lengths tree";
                goto label_6;

            default:
                num2 = bb[0] != 0 ? 1 : 0;
                break;
            }
            if (num2 == 0)
            {
                z.ErrorMessage = "incomplete dynamic bit lengths tree";
                num1           = -3;
            }
label_6:
            return(num1);
        }
Exemple #3
0
 private void ProcessTypeFixed(CompressionStream zip, InflaterBlocksContext state)
 {
     int[]   bl = new int[1];
     int[]   bd = new int[1];
     int[][] tl = new int[1][];
     int[][] td = new int[1][];
     InflaterTree.InflateTreeFixed(bl, bd, tl, td, zip);
     this.codes = new InflaterCodes(bl[0], bd[0], tl[0], td[0], zip);
     state.ShiftRight(3);
     this.mode = 6;
 }
Exemple #4
0
 private int ProcessBTree(CompressionStream zip, InflaterBlocksContext state, int res)
 {
     while (this.index < 4 + Utils.ShiftRight(this.table, 10))
     {
         for (; state.Bits < 3; state.Bits += 8)
         {
             if (state.BytesCount != 0)
             {
                 res = 0;
                 --state.BytesCount;
                 state.BitBuf |= ((int)zip.Input[state.Input++] & (int)byte.MaxValue) << state.Bits;
             }
             else
             {
                 this.TransferBlocksState(zip, state);
                 state.IsReturn = true;
                 return(this.InflateFlush(zip, res));
             }
         }
         this.blens[InflaterBlocks.border[this.index++]] = state.BitBuf & 7;
         state.ShiftRight(3);
     }
     while (this.index < 19)
     {
         this.blens[InflaterBlocks.border[this.index++]] = 0;
     }
     this.bitLengthTreeDepth[0] = 7;
     state.Temp = InflaterTree.InflateTreeBits(this.blens, this.bitLengthTreeDepth, this.bitLengthDecodeTree, this.hufts, zip);
     if (state.Temp != 0)
     {
         res = state.Temp;
         if (res == -3)
         {
             this.blens = (int[])null;
             this.mode  = 9;
         }
         this.TransferBlocksState(zip, state);
         state.IsReturn = true;
         return(this.InflateFlush(zip, res));
     }
     this.index = 0;
     this.mode  = 5;
     return(0);
 }
Exemple #5
0
        private int ProcessDTree(CompressionStream zip, InflaterBlocksContext state, int res)
        {
            while (true)
            {
                state.Temp = this.table;
                if (this.index < 258 + (state.Temp & 31) + (state.Temp >> 5 & 31))
                {
                    for (state.Temp = this.bitLengthTreeDepth[0]; state.Bits < state.Temp; state.Bits += 8)
                    {
                        if (state.BytesCount != 0)
                        {
                            res = 0;
                            --state.BytesCount;
                            state.BitBuf |= ((int)zip.Input[state.Input++] & (int)byte.MaxValue) << state.Bits;
                        }
                        else
                        {
                            this.TransferBlocksState(zip, state);
                            state.IsReturn = true;
                            return(this.InflateFlush(zip, res));
                        }
                    }
                    state.Temp = this.hufts[(this.bitLengthDecodeTree[0] + (state.BitBuf & InflaterBlocks.inflateMask[state.Temp])) * 3 + 1];
                    int huft = this.hufts[(this.bitLengthDecodeTree[0] + (state.BitBuf & InflaterBlocks.inflateMask[state.Temp])) * 3 + 2];
                    if (huft < 16)
                    {
                        state.ShiftRight(state.Temp);
                        this.blens[this.index++] = huft;
                    }
                    else
                    {
                        int v    = huft == 18 ? 7 : huft - 14;
                        int num1 = huft == 18 ? 11 : 3;
                        for (; state.Bits < state.Temp + v; state.Bits += 8)
                        {
                            if (state.BytesCount != 0)
                            {
                                res = 0;
                                --state.BytesCount;
                                state.BitBuf |= ((int)zip.Input[state.Input++] & (int)byte.MaxValue) << state.Bits;
                            }
                            else
                            {
                                this.TransferBlocksState(zip, state);
                                state.IsReturn = true;
                                return(this.InflateFlush(zip, res));
                            }
                        }
                        state.ShiftRight(state.Temp);
                        int num2 = num1 + (state.BitBuf & InflaterBlocks.inflateMask[v]);
                        state.ShiftRight(v);
                        int index = this.index;
                        state.Temp = this.table;
                        if (index + num2 <= 258 + (state.Temp & 31) + (state.Temp >> 5 & 31) && (huft != 16 || index >= 1))
                        {
                            int num3 = huft == 16 ? this.blens[index - 1] : 0;
                            do
                            {
                                this.blens[index++] = num3;
                            }while (--num2 != 0);
                            this.index = index;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                else
                {
                    goto label_20;
                }
            }
            this.blens       = (int[])null;
            this.mode        = 9;
            zip.ErrorMessage = "invalid bit length repeat";
            res = -3;
            this.TransferBlocksState(zip, state);
            state.IsReturn = true;
            return(this.InflateFlush(zip, res));

label_20:
            this.bitLengthDecodeTree[0] = -1;
            int[] bl = new int[1];
            int[] bd = new int[1];
            int[] tl = new int[1];
            int[] td = new int[1];
            bl[0]      = 9;
            bd[0]      = 6;
            state.Temp = this.table;
            state.Temp = InflaterTree.InflateTreeDynamic(257 + (state.Temp & 31), 1 + (state.Temp >> 5 & 31), this.blens, bl, bd, tl, td, this.hufts, zip);
            if (state.Temp != 0)
            {
                if (state.Temp == -3)
                {
                    this.blens = (int[])null;
                    this.mode  = 9;
                }
                res = state.Temp;
                this.TransferBlocksState(zip, state);
                state.IsReturn = true;
                return(this.InflateFlush(zip, res));
            }
            this.codes = new InflaterCodes(bl[0], bd[0], this.hufts, tl[0], this.hufts, td[0], zip);
            this.mode  = 6;
            return(0);
        }