internal static void HandlePK00Prefix(Stream s) { // in some cases, the zip file begins with "PK00". This is a throwback and is rare, // but we handle it anyway. We do not change behavior based on it. uint datum = (uint)SharedUtilities.ReadInt(s); if (datum != ZipConstants.PackedToRemovableMedia) { s.Seek(-4, SeekOrigin.Current); // unread the block // workitem 10178 SharedUtilities.Workaround_Ladybug318918(s); } }
private static void HandleUnexpectedDataDescriptor(ZipEntry entry) { Stream s = entry.ArchiveStream; // In some cases, the "data descriptor" is present, without a signature, even when // bit 3 of the BitField is NOT SET. This is the CRC, followed // by the compressed length and the uncompressed length (4 bytes for each // of those three elements). Need to check that here. // uint datum = (uint)SharedUtilities.ReadInt(s); if (datum == entry._Crc32) { int sz = SharedUtilities.ReadInt(s); if (sz == entry._CompressedSize) { sz = SharedUtilities.ReadInt(s); if (sz == entry._UncompressedSize) { // ignore everything and discard it. } else { s.Seek(-12, SeekOrigin.Current); // unread the three blocks // workitem 10178 SharedUtilities.Workaround_Ladybug318918(s); } } else { s.Seek(-8, SeekOrigin.Current); // unread the two blocks // workitem 10178 SharedUtilities.Workaround_Ladybug318918(s); } } else { s.Seek(-4, SeekOrigin.Current); // unread the block // workitem 10178 SharedUtilities.Workaround_Ladybug318918(s); } }
private static void Zip64SeekToCentralDirectory(ZipFile zf) { Stream s = zf.ReadStream; byte[] block = new byte[16]; // seek back to find the ZIP64 EoCD. // I think this might not work for .NET CF ? s.Seek(-40, SeekOrigin.Current); s.Read(block, 0, 16); Int64 offset64 = BitConverter.ToInt64(block, 8); zf._OffsetOfCentralDirectory = 0xFFFFFFFF; zf._OffsetOfCentralDirectory64 = offset64; // change for workitem 8098 s.Seek(offset64, SeekOrigin.Begin); //zf.SeekFromOrigin(Offset64); uint datum = (uint)SharedUtilities.ReadInt(s); if (datum != ZipConstants.Zip64EndOfCentralDirectoryRecordSignature) { throw new BadReadException(String.Format(" Bad signature (0x{0:X8}) looking for ZIP64 EoCD Record at position 0x{1:X8}", datum, s.Position)); } s.Read(block, 0, 8); Int64 Size = BitConverter.ToInt64(block, 0); block = new byte[Size]; s.Read(block, 0, block.Length); offset64 = BitConverter.ToInt64(block, 36); // change for workitem 8098 s.Seek(offset64, SeekOrigin.Begin); //zf.SeekFromOrigin(Offset64); }
private static uint ReadFirstFourBytes(Stream s) { uint datum = (uint)SharedUtilities.ReadInt(s); return(datum); }