Example #1
0
 private void CompleteCloseEntry(bool testCrc = false)
 {
     StopDecrypting();
     if ((_flags & 8) != 0)
     {
         ReadDataDescriptor();
     }
     _size = 0L;
     if ((testCrc && ((((ulong)_crc.Value) & 0xffffffffL) != (ulong)_entry.Crc)) && (_entry.Crc != -1L))
     {
         throw new ZipException("CRC mismatch");
     }
     _crc.Reset();
     if (_method == 8)
     {
         Inf.Reset();
     }
     _entry = null;
 }
Example #2
0
        /*
         * Reads GZIP member trailer and returns true if the eos
         * reached, false if there are more (concatenated gzip
         * data set)
         */
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private boolean readTrailer() throws java.io.IOException
        private bool ReadTrailer()
        {
            InputStream @in = this.@in;
            int         n   = Inf.Remaining;

            if (n > 0)
            {
                @in = new SequenceInputStream(new ByteArrayInputStream(Buf, Len - n, n), new FilterInputStreamAnonymousInnerClassHelper(this, @in));
            }
            // Uses left-to-right evaluation order
            if ((ReadUInt(@in) != Crc.Value) || (ReadUInt(@in) != (Inf.BytesWritten & 0xffffffffL)))
            {
                // rfc1952; ISIZE is the input size modulo 2^32
                throw new ZipException("Corrupt GZIP trailer");
            }

            // If there are more bytes available in "in" or
            // the leftover in the "inf" is > 26 bytes:
            // this.trailer(8) + next.header.min(10) + next.trailer(8)
            // try concatenated case
            if ([email protected]() > 0 || n > 26)
            {
                int m = 8;                 // this.trailer
                try
                {
                    m += ReadHeader(@in);                     // next.header
                }
                catch (IOException)
                {
                    return(true);                    // ignore any malformed, do nothing
                }
                Inf.Reset();
                if (n > m)
                {
                    Inf.SetInput(Buf, Len - n + m, n - m);
                }
                return(false);
            }
            return(true);
        }
Example #3
0
        private void ReadFooter()
        {
            int num3;

            byte[] outBuffer = new byte[8];
            long   num       = Inf.TotalOut & 0xffffffffL;

            InputBuffer.Available += Inf.RemainingInput;
            Inf.Reset();
            for (int i = 8; i > 0; i -= num3)
            {
                num3 = InputBuffer.ReadClearTextBuffer(outBuffer, 8 - i, i);
                if (num3 <= 0)
                {
                    throw new EndOfStreamException("EOS reading GZIP footer");
                }
            }
            int num4
                = (((outBuffer[0] & 0xff) | ((outBuffer[1] & 0xff) << 8))
                   | ((outBuffer[2] & 0xff) << GZipConstants.FCOMMENT)) | (outBuffer[3] << 0x18);

            if (num4 != ((int)_crc.Value))
            {
                throw new GZipException(string.Concat(new object[]
                {
                    "GZIP crc sum mismatch, theirs \"", num4, "\" and ours \"", (int)_crc.Value
                }));
            }
            uint num5 = (uint)((((outBuffer[4] & 0xff) | ((outBuffer[5] & 0xff) << 8))
                                | ((outBuffer[6] & 0xff) << GZipConstants.FCOMMENT)) | (outBuffer[7] << 0x18));

            if (num != num5)
            {
                throw new GZipException("Number of bytes mismatch in footer");
            }
            _readGzipHeader = false;
        }
Example #4
0
        private int BodyRead(byte[] buffer, int offset, int count)
        {
            if (_crc == null)
            {
                throw new InvalidOperationException("Closed");
            }
            if ((_entry == null) || (count <= 0))
            {
                return(0);
            }
            if ((offset + count) > buffer.Length)
            {
                throw new ArgumentException("Offset + count exceeds buffer size");
            }
            var flag = false;

            switch (_method)
            {
            case 0:
                if ((count > Csize) && (Csize >= 0L))
                {
                    count = (int)Csize;
                }
                if (count > 0)
                {
                    count = InputBuffer.ReadClearTextBuffer(buffer, offset, count);
                    if (count > 0)
                    {
                        Csize -= count;
                        _size -= count;
                    }
                }
                if (Csize == 0L)
                {
                    flag = true;
                }
                else if (count < 0)
                {
                    throw new ZipException("EOF in stored block");
                }
                break;

            case 8:
                count = base.Read(buffer, offset, count);
                if (count <= 0)
                {
                    if (!Inf.IsFinished)
                    {
                        throw new ZipException("Inflater not finished!");
                    }
                    InputBuffer.Available = Inf.RemainingInput;
                    if (((_flags & 8) == 0) && ((((Inf.TotalIn != Csize) && (Csize != 0xffffffffL)) && (Csize != -1L)) || (Inf.TotalOut != _size)))
                    {
                        throw new ZipException(string.Concat("Size mismatch: ", Csize, ";", _size, " <-> ", Inf.TotalIn, ";", Inf.TotalOut));
                    }
                    Inf.Reset();
                    flag = true;
                }
                break;
            }
            if (count > 0)
            {
                _crc.Update(buffer, offset, count);
            }
            if (flag)
            {
                CompleteCloseEntry(true);
            }
            return(count);
        }