private void checkZipFileSignature(final ReadOnlyFile rof) throws IOException { final byte[] sig = new byte[4]; rof.seek(this.preamble); rof.readFully(sig); final long signature = readUInt(sig, 0); // Constraint: A ZIP file must start with a Local File Header // or a (ZIP64) End Of Central Directory Record iff it's emtpy. if (LFH_SIG != signature && ZIP64_EOCDR_SIG != signature && EOCDR_SIG != signature) throw new ZipException( "Expected Local File Header or (ZIP64) End Of Central Directory Record!"); }
rof.seek(eocdrOff); rof.readFully(sig); if (EOCDR_SIG != readUInt(sig, 0)) continue; throw new ZipException( "ZIP file spanning/splitting is not supported!"); cdSize = readUInt(eocdr, off); off += 4; cdOffset = readUInt(eocdr, off); off += 4; commentLen = readUShort(eocdr, off); final byte[] zip64eocdl = new byte[ZIP64_EOCDL_LEN]; rof.readFully(zip64eocdl); if (ZIP64_EOCDL_SIG != readUInt(zip64eocdl, 0)) { final long totalDisks; // total number of disks off = 4; // reuse zip64eocdrDisk = readUInt(zip64eocdl, off); off += 4; zip64eocdrOff = readLong(zip64eocdl, off); off += 8; totalDisks = readUInt(zip64eocdl, off); if (ZIP64_EOCDR_SIG != readUInt(zip64eocdr, off)) throw new ZipException( "Expected ZIP64 End Of Central Directory Record!");
@Test public void testUInt() { final long i = readUInt(read, 1); assertEquals(0xaa55aa55L, i); writeInt((int) i, write, 1); writeInt((int) i, write, 5); assertTrue(Arrays.equals(read, write)); }
rof.readFully(cfh, 0, 4); if (CFH_SIG != readUInt(cfh, 0)) break; rof.readFully(cfh, 4, CFH_MIN_LEN - 4); entry.setRawTime(readUInt(cfh, off)); off += 4; entry.setRawCrc(readUInt(cfh, off)); off += 4; entry.setRawCompressedSize(readUInt(cfh, off)); off += 4; entry.setRawSize(readUInt(cfh, off)); off += 4; entry.setRawExternalAttributes(readUInt(cfh, off)); off += 4; long lfhOff = readUInt(cfh, off);
final byte[] lfh = new byte[LFH_MIN_LEN]; rof.readFully(lfh); if (LFH_SIG != readUInt(lfh, 0)) throw new ZipException(name + " (expected Local File Header)"); fp += LFH_MIN_LEN rof.seek(fp + entry.getCompressedSize()); rof.readFully(dd); localCrc = readUInt(dd, 0); if (DD_SIG == localCrc) localCrc = readUInt(dd, 4); } else { localCrc = readUInt(lfh, 14);
final byte[] lfh = new byte[LFH_MIN_LEN]; rof.readFully(lfh); if (LFH_SIG != readUInt(lfh, 0)) throw new ZipException("Expected Local File Header!"); final int gpbf = readUShort(lfh, 6); entry.setRawTime(readUInt(lfh, off)); off += 4; entry.setRawCrc(readUInt(lfh, off)); off += 4; entry.setRawCompressedSize(readUInt(lfh, off)); off += 4; entry.setRawSize(readUInt(lfh, off)); off += 4; rof.seek(fp); rof.readFully(dd, 0, 4); long crc = readUInt(dd, 0); else rof.readFully(dd, 4, dd.length - 4); crc = readUInt(dd, 0); final long csize; final long size; size = readLong(dd, 12);