示例#1
0
 internal bool LoadLocalHeaderExtraFieldAndCompressedBytesIfNeeded()
 {
     if (this._originallyInArchive)
     {
         this._archive.ArchiveStream.Seek(this._offsetOfLocalHeader, SeekOrigin.Begin);
         this._lhUnknownExtraFields = ZipLocalFileHeader.GetExtraFields(this._archive.ArchiveReader);
     }
     if (!this._everOpenedForWrite && this._originallyInArchive)
     {
         this._compressedBytes = new byte[checked ((IntPtr)this._compressedSize)];
         this._archive.ArchiveStream.Seek(this.OffsetOfCompressedData, SeekOrigin.Begin);
         ZipHelper.ReadBytes(this._archive.ArchiveStream, this._compressedBytes, (int)this._compressedSize);
     }
     return(true);
 }
示例#2
0
 private bool IsOpenable(bool needToUncompress, bool needToLoadIntoMemory, out string message)
 {
     message = null;
     if (this._originallyInArchive)
     {
         if (needToUncompress && this.CompressionMethod != ZipArchiveEntry.CompressionMethodValues.Stored && this.CompressionMethod != ZipArchiveEntry.CompressionMethodValues.Deflate)
         {
             message = Messages.UnsupportedCompression;
             return(false);
         }
         if ((long)this._diskNumberStart != (ulong)this._archive.NumberOfThisDisk)
         {
             message = Messages.SplitSpanned;
             return(false);
         }
         if (this._offsetOfLocalHeader > this._archive.ArchiveStream.Length)
         {
             message = Messages.LocalFileHeaderCorrupt;
             return(false);
         }
         this._archive.ArchiveStream.Seek(this._offsetOfLocalHeader, SeekOrigin.Begin);
         if (!ZipLocalFileHeader.TrySkipBlock(this._archive.ArchiveReader))
         {
             message = Messages.LocalFileHeaderCorrupt;
             return(false);
         }
         if (this.OffsetOfCompressedData + this._compressedSize > this._archive.ArchiveStream.Length)
         {
             message = Messages.LocalFileHeaderCorrupt;
             return(false);
         }
         if (needToLoadIntoMemory && this._compressedSize > (long)2147483647)
         {
             message = Messages.EntryTooLarge;
             return(false);
         }
     }
     return(true);
 }
示例#3
0
        // returns false if fails, will get called on every entry before closing in update mode
        // can throw InvalidDataException
        internal bool LoadLocalHeaderExtraFieldAndCompressedBytesIfNeeded()
        {
            string message;

            // we should have made this exact call in _archive.Init through ThrowIfOpenable
            Debug.Assert(IsOpenable(false, true, out message));

            // load local header's extra fields. it will be null if we couldn't read for some reason
            if (_originallyInArchive)
            {
                _archive.ArchiveStream.Seek(_offsetOfLocalHeader, SeekOrigin.Begin);

                _lhUnknownExtraFields = ZipLocalFileHeader.GetExtraFields(_archive.ArchiveReader);
            }

            if (!_everOpenedForWrite && _originallyInArchive)
            {
                // we know that it is openable at this point

                _compressedBytes = new byte[(_compressedSize / MaxSingleBufferSize) + 1][];
                for (int i = 0; i < _compressedBytes.Length - 1; i++)
                {
                    _compressedBytes[i] = new byte[MaxSingleBufferSize];
                }
                _compressedBytes[_compressedBytes.Length - 1] = new byte[_compressedSize % MaxSingleBufferSize];

                _archive.ArchiveStream.Seek(OffsetOfCompressedData, SeekOrigin.Begin);

                for (int i = 0; i < _compressedBytes.Length - 1; i++)
                {
                    ZipHelper.ReadBytes(_archive.ArchiveStream, _compressedBytes[i], MaxSingleBufferSize);
                }
                ZipHelper.ReadBytes(_archive.ArchiveStream, _compressedBytes[_compressedBytes.Length - 1], (int)(_compressedSize % MaxSingleBufferSize));
            }

            return(true);
        }
示例#4
0
        private bool IsOpenable(bool needToUncompress, bool needToLoadIntoMemory, out string message)
        {
            message = null;

            if (_originallyInArchive)
            {
                if (needToUncompress)
                {
                    if (CompressionMethod != CompressionMethodValues.Stored &&
                        CompressionMethod != CompressionMethodValues.Deflate &&
                        CompressionMethod != CompressionMethodValues.Deflate64)
                    {
                        switch (CompressionMethod)
                        {
                        case CompressionMethodValues.BZip2:
                        case CompressionMethodValues.LZMA:
                            message = "";
                            break;

                        default:
                            message = "";
                            break;
                        }
                        return(false);
                    }
                }
                if (_diskNumberStart != _archive.NumberOfThisDisk)
                {
                    message = "";
                    return(false);
                }
                if (_offsetOfLocalHeader > _archive.ArchiveStream.Length)
                {
                    message = "";
                    return(false);
                }
                _archive.ArchiveStream.Seek(_offsetOfLocalHeader, SeekOrigin.Begin);
                if (!ZipLocalFileHeader.TrySkipBlock(_archive.ArchiveReader))
                {
                    message = "";
                    return(false);
                }
                // when this property gets called, some duplicated work
                if (OffsetOfCompressedData + _compressedSize > _archive.ArchiveStream.Length)
                {
                    message = "";
                    return(false);
                }
                // This limitation originally existed because a) it is unreasonable to load > 4GB into memory
                // but also because the stream reading functions make it hard.  This has been updated to handle
                // this scenario in a 64-bit process using multiple buffers, delivered first as an OOB for
                // compatibility.
                if (needToLoadIntoMemory)
                {
                    if (_compressedSize > int.MaxValue)
                    {
                        if (!s_allowLargeZipArchiveEntriesInUpdateMode)
                        {
                            message = "";
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }