internal void ProcessExtraData(bool localHeader) { ZipExtraData extraData = new ZipExtraData(this.extra); if (extraData.Find(1)) { this.forceZip64_ = true; if (extraData.ValueLength < 4) { throw new ZipException("Extra data extended Zip64 information length is invalid"); } if (localHeader || (this.size == 0xffffffffL)) { this.size = (ulong) extraData.ReadLong(); } if (localHeader || (this.compressedSize == 0xffffffffL)) { this.compressedSize = (ulong) extraData.ReadLong(); } if (!(localHeader || (this.offset != 0xffffffffL))) { this.offset = extraData.ReadLong(); } } else if (((this.versionToExtract & 0xff) >= 0x2d) && ((this.size == 0xffffffffL) || (this.compressedSize == 0xffffffffL))) { throw new ZipException("Zip64 Extended information required but is missing."); } if (extraData.Find(10)) { if (extraData.ValueLength < 4) { throw new ZipException("NTFS Extra data invalid"); } extraData.ReadInt(); while (extraData.UnreadCount >= 4) { int num = extraData.ReadShort(); int amount = extraData.ReadShort(); if (num == 1) { if (amount >= 0x18) { long fileTime = extraData.ReadLong(); long num4 = extraData.ReadLong(); long num5 = extraData.ReadLong(); this.DateTime = System.DateTime.FromFileTime(fileTime); } break; } extraData.Skip(amount); } } else if (extraData.Find(0x5455)) { int valueLength = extraData.ValueLength; if (((extraData.ReadByte() & 1) != 0) && (valueLength >= 5)) { int seconds = extraData.ReadInt(); System.DateTime time = new System.DateTime(0x7b2, 1, 1, 0, 0, 0); this.DateTime = (time.ToUniversalTime() + new TimeSpan(0, 0, 0, seconds, 0)).ToLocalTime(); } } if (this.method == Maticsoft.ZipLib.Zip.CompressionMethod.WinZipAES) { this.ProcessAESExtraData(extraData); } }
private long TestLocalHeader(ZipEntry entry, HeaderTest tests) { lock (this.baseStream_) { bool flag = (tests & HeaderTest.Header) != 0; bool flag2 = (tests & HeaderTest.Extract) != 0; this.baseStream_.Seek(this.offsetOfFirstEntry + entry.Offset, SeekOrigin.Begin); if (this.ReadLEUint() != 0x4034b50) { throw new ZipException(string.Format("Wrong local header signature @{0:X}", this.offsetOfFirstEntry + entry.Offset)); } short num = (short) this.ReadLEUshort(); short flags = (short) this.ReadLEUshort(); short num3 = (short) this.ReadLEUshort(); short num4 = (short) this.ReadLEUshort(); short num5 = (short) this.ReadLEUshort(); uint num6 = this.ReadLEUint(); long num7 = this.ReadLEUint(); long num8 = this.ReadLEUint(); int num9 = this.ReadLEUshort(); int num10 = this.ReadLEUshort(); byte[] buffer = new byte[num9]; StreamUtils.ReadFully(this.baseStream_, buffer); byte[] buffer2 = new byte[num10]; StreamUtils.ReadFully(this.baseStream_, buffer2); ZipExtraData data = new ZipExtraData(buffer2); if (data.Find(1)) { num8 = data.ReadLong(); num7 = data.ReadLong(); if ((flags & 8) != 0) { if ((num8 != -1L) && (num8 != entry.Size)) { throw new ZipException("Size invalid for descriptor"); } if ((num7 != -1L) && (num7 != entry.CompressedSize)) { throw new ZipException("Compressed size invalid for descriptor"); } } } else if ((num >= 0x2d) && ((((uint) num8) == uint.MaxValue) || (((uint) num7) == uint.MaxValue))) { throw new ZipException("Required Zip64 extended information missing"); } if (flag2 && entry.IsFile) { if (!entry.IsCompressionMethodSupported()) { throw new ZipException("Compression method not supported"); } if ((num > 0x33) || ((num > 20) && (num < 0x2d))) { throw new ZipException(string.Format("Version required to extract this entry not supported ({0})", num)); } if ((flags & 0x3060) != 0) { throw new ZipException("The library does not support the zip version required to extract this entry"); } } if (flag) { if ((((((num <= 0x3f) && (num != 10)) && ((num != 11) && (num != 20))) && (((num != 0x15) && (num != 0x19)) && ((num != 0x1b) && (num != 0x2d)))) && ((((num != 0x2e) && (num != 50)) && ((num != 0x33) && (num != 0x34))) && ((num != 0x3d) && (num != 0x3e)))) && (num != 0x3f)) { throw new ZipException(string.Format("Version required to extract this entry is invalid ({0})", num)); } if ((flags & 0xc010) != 0) { throw new ZipException("Reserved bit flags cannot be set."); } if (((flags & 1) != 0) && (num < 20)) { throw new ZipException(string.Format("Version required to extract this entry is too low for encryption ({0})", num)); } if ((flags & 0x40) != 0) { if ((flags & 1) == 0) { throw new ZipException("Strong encryption flag set but encryption flag is not set"); } if (num < 50) { throw new ZipException(string.Format("Version required to extract this entry is too low for encryption ({0})", num)); } } if (((flags & 0x20) != 0) && (num < 0x1b)) { throw new ZipException(string.Format("Patched data requires higher version than ({0})", num)); } if (flags != entry.Flags) { throw new ZipException("Central header/local header flags mismatch"); } if (entry.CompressionMethod != ((CompressionMethod) num3)) { throw new ZipException("Central header/local header compression method mismatch"); } if (entry.Version != num) { throw new ZipException("Extract version mismatch"); } if (((flags & 0x40) != 0) && (num < 0x3e)) { throw new ZipException("Strong encryption flag set but version not high enough"); } if (((flags & 0x2000) != 0) && ((num4 != 0) || (num5 != 0))) { throw new ZipException("Header masked set but date/time values non-zero"); } if (((flags & 8) == 0) && (num6 != ((uint) entry.Crc))) { throw new ZipException("Central header/local header crc mismatch"); } if (((num8 == 0L) && (num7 == 0L)) && (num6 != 0)) { throw new ZipException("Invalid CRC for empty entry"); } if (entry.Name.Length > num9) { throw new ZipException("File name length mismatch"); } string name = ZipConstants.ConvertToStringExt(flags, buffer); if (name != entry.Name) { throw new ZipException("Central header and local header file name mismatch"); } if (entry.IsDirectory) { if (num8 > 0L) { throw new ZipException("Directory cannot have size"); } if (entry.IsCrypted) { if (num7 > 14L) { throw new ZipException("Directory compressed size invalid"); } } else if (num7 > 2L) { throw new ZipException("Directory compressed size invalid"); } } if (!ZipNameTransform.IsValidName(name, true)) { throw new ZipException("Name is invalid"); } } if (((flags & 8) == 0) || ((num8 > 0L) || (num7 > 0L))) { if (num8 != entry.Size) { throw new ZipException(string.Format("Size mismatch between central header({0}) and local header({1})", entry.Size, num8)); } if (((num7 != entry.CompressedSize) && (num7 != 0xffffffffL)) && (num7 != -1L)) { throw new ZipException(string.Format("Compressed size mismatch between central header({0}) and local header({1})", entry.CompressedSize, num7)); } } int num11 = num9 + num10; return (((this.offsetOfFirstEntry + entry.Offset) + 30L) + num11); } }