internal void ProcessExtraData(bool localHeader) { ZipExtraData extraData = new ZipExtraData(extra); if (extraData.Find(1)) { forceZip64_ = true; if (extraData.ValueLength < 4) { throw new ZipException("Extra data extended Zip64 information length is invalid"); } if (localHeader || (size == 0xffffffffL)) { size = (ulong)extraData.ReadLong(); } if (localHeader || (compressedSize == 0xffffffffL)) { compressedSize = (ulong)extraData.ReadLong(); } if (!localHeader && (offset == 0xffffffffL)) { offset = extraData.ReadLong(); } } else if (((versionToExtract & 0xff) >= 0x2d) && ((size == 0xffffffffL) || (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(); extraData.ReadLong(); extraData.ReadLong(); DateTime = 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(); DateTime time = new DateTime(0x7b2, 1, 1, 0, 0, 0); DateTime = (time.ToUniversalTime() + new TimeSpan(0, 0, 0, seconds, 0)).ToLocalTime(); } } if (method == CompressionMethod.WinZipAES) { ProcessAESExtraData(extraData); } }
private long TestLocalHeader(ZipEntry entry, HeaderTest tests) { lock (baseStream_) { bool flag = (tests & HeaderTest.Header) != 0; bool flag2 = (tests & HeaderTest.Extract) != 0; baseStream_.Seek(offsetOfFirstEntry + entry.Offset, SeekOrigin.Begin); if (ReadLEUint() != 0x4034b50) { throw new ZipException(string.Format("Wrong local header signature @{0:X}", offsetOfFirstEntry + entry.Offset)); } short num = (short)ReadLEUshort(); short flags = (short)ReadLEUshort(); short num3 = (short)ReadLEUshort(); short num4 = (short)ReadLEUshort(); short num5 = (short)ReadLEUshort(); uint num6 = ReadLEUint(); long num7 = ReadLEUint(); long num8 = ReadLEUint(); int num9 = ReadLEUshort(); int num10 = ReadLEUshort(); byte[] buffer = new byte[num9]; StreamUtils.ReadFully(baseStream_, buffer); byte[] buffer2 = new byte[num10]; StreamUtils.ReadFully(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 (((offsetOfFirstEntry + entry.Offset) + 30L) + num11); } }