public static boolean isZipBomb(ZipEntry entry) { long compressedSize = entry.getCompressedSize(); long uncompressedSize = entry.getSize(); if (compressedSize < 0 || uncompressedSize < 0) { LOG.error("Zip bomb attack detected, invalid sizes: compressed {}, uncompressed {}, name {}", compressedSize, uncompressedSize, entry.getName()); return true; } if (compressedSize * MAX_SIZE_DIFF < uncompressedSize) { LOG.error("Zip bomb attack detected, invalid sizes: compressed {}, uncompressed {}, name {}", compressedSize, uncompressedSize, entry.getName()); return true; } return false; }
@Override public long getCompressedSize(String fileName) throws DirectoryException { ZipEntry entry = getZipFileEntry(fileName); return entry.getCompressedSize(); }
long guessOffsetFor(ZipFile zipFile, ZipEntry zipEntry) { Enumeration<? extends ZipEntry> zipEntries = zipFile.entries(); long offset = 0; while (zipEntries.hasMoreElements()) { ZipEntry entry = zipEntries.nextElement(); long fileSize = 0; long extra = entry.getExtra() == null ? 0 : entry.getExtra().length; offset += 30 + entry.getName().length() + extra; if (entry.getName().equals(zipEntry.getName())) { return offset; } if(!entry.isDirectory()) { fileSize = entry.getCompressedSize(); // Do stuff here with fileSize & offset } offset += fileSize; } throw new IllegalStateException("'" + zipEntry.getName() + "' not found"); } /*
} else { double factor = 1; if (ze.getCompressedSize() > 0 && ze.getSize() > 0) factor = (double) ze.getCompressedSize() / ze.getSize();
FileMap createEntryFileMap(ZipEntryRO entry) { // final _ZipEntryRO *zipEntry = reinterpret_cast<_ZipEntryRO*>(entry); // const ZipEntry& ze = zipEntry->entry; ZipEntry ze = entry.entry; // int fd = GetFileDescriptor(mHandle); int fd = -1; int actualLen = 0; if (ze.getMethod() == kCompressStored) { actualLen = toIntExact(ze.getSize()); } else { actualLen = toIntExact(ze.getCompressedSize()); } FileMap newMap = new FileMap(); if (!newMap.createFromZip(mFileName, mHandle.zipFile, entry.entry, actualLen, true)) { // delete newMap; return null; } return newMap; }
boolean getEntryInfo(org.robolectric.res.android.ZipFileRO.ZipEntryRO entry, Ref<Short> pMethod, final Ref<Long> pUncompLen, Ref<Long> pCompLen, Ref<Long> pOffset, final Ref<Long> pModWhen, Ref<Long> pCrc32) { final ZipEntryRO zipEntry = /*reinterpret_cast<ZipEntryRO*>*/(entry); final ZipEntry ze = zipEntry.entry; if (pMethod != null) { pMethod.set((short) ze.getMethod()); } if (pUncompLen != null) { pUncompLen.set(ze.getSize()); // uncompressed_length } if (pCompLen != null) { pCompLen.set(ze.getCompressedSize()); } if (pOffset != null) { throw new UnsupportedOperationException("Figure out offset"); // pOffset = ze.offset; } if (pModWhen != null) { // todo pModWhen.set(ze.getLastModifiedTime().toMillis()); } if (pCrc32 != null) { pCrc32.set(ze.getCrc()); } return true; }
private static ArrayMemory zipEntryToArray(ZipEntry zipEntry) { final ArrayMemory result = new ArrayMemory(); result.refOfIndex("name").assign(zipEntry.getName()); result.refOfIndex("crc").assign(zipEntry.getCrc()); result.refOfIndex("size").assign(zipEntry.getSize()); result.refOfIndex("compressedSize").assign(zipEntry.getCompressedSize()); result.refOfIndex("time").assign(zipEntry.getTime()); result.refOfIndex("method").assign(zipEntry.getMethod()); result.refOfIndex("comment").assign(zipEntry.getComment()); result.refOfIndex("directory").assign(zipEntry.isDirectory()); return result; }
if (ze.getCompressedSize() == -1) { ze.setCompressedSize(ze.getSize()); } else if (ze.getSize() == -1) { ze.setSize(ze.getCompressedSize());
long compressedSize = zipEntry.getCompressedSize(); log.trace("Unzipping {} (size: {} KB, compressed size: {} KB)", name, size, compressedSize);
/** * Returns the size of the compressed data. * * @return -1, or compressed size */ public long zip_entry_compressedsize() { if (_entry == null) return -1; return _entry.getCompressedSize(); }
public long getCompressedSize() { return entry.getCompressedSize(); }
ByteArrayInputStream bis = new ByteArrayInputStream(byteArray); ZipInputStream zis = new ZipInputStream(bis); ZipEntry entry = zis.getNextEntry(); InputSource inputSource = new InputSource(new BoundedInputStream(zis, entry.getCompressedSize()));
Enumeration<? extends ZipEntry> zipEntries = zipFile.entries(); long offset = 0; while (zipEntries.hasMoreElements()) { ZipEntry entry = (ZipEntry)zipEntries.nextElement(); long fileSize = 0; long extra = entry.getExtra() == null ? 0 : entry.getExtra().length; offset += 30 + entry.getName().length() + extra; if(!entry.isDirectory()) { fileSize = entry.getCompressedSize(); // Do stuff here with fileSize & offset } offset += fileSize; }
@Nullable public Bytes getCompressedSize() { long size = getHandle().getCompressedSize(); return size != -1 ? new Bytes(size) : null; }
@Nullable public Bytes getCompressedSize() { long size = getHandle().getCompressedSize(); return size != -1 ? new Bytes(size) : null; }
public XEntry(ZipEntry entry, long offset) { this.entry = entry; this.offset = offset; // store size, compressed size, and crc-32 in data descriptor // immediately following the compressed entry data // store size, compressed size, and crc-32 in LOC header this.flag = (entry.getMethod() == DEFLATED && (entry.getSize() == -1 || entry.getCompressedSize() == -1 || entry.getCrc() == -1))? 8: 0; } }
public ZippedEntry(ZipEntry e, InputStream is) { this.name = e.getName(); this.time = e.getTime(); // this.mtime = e.getLastModifiedTime(); // this.atime = e.getLastAccessTime(); // this.ctime = e.getCreationTime(); this.crc = e.getCrc(); this.size = e.getSize(); this.csize = e.getCompressedSize(); this.method = e.getMethod(); this.extra = e.getExtra(); this.comment = e.getComment(); this.is = is; }
public ZippedEntry(ZipEntry e, InputStream is) { this.name = e.getName(); this.time = e.getTime(); // this.mtime = e.getLastModifiedTime(); // this.atime = e.getLastAccessTime(); // this.ctime = e.getCreationTime(); this.crc = e.getCrc(); this.size = e.getSize(); this.csize = e.getCompressedSize(); this.method = e.getMethod(); this.extra = e.getExtra(); this.comment = e.getComment(); this.is = is; }
private void writeEXT(ZipEntry e) throws IOException { writeInt(EXTSIG); // EXT header signature writeInt(e.getCrc()); // crc-32 writeInt(e.getCompressedSize()); // compressed size writeInt(e.getSize()); // uncompressed size }
public ZipEntryMatrix(ZipFile zipFile, ZipEntry zipEntry) { this.zipFile = zipFile; this.zipEntry = zipEntry; setLabel(zipEntry.getName()); setMetaData("CompressedSize", zipEntry.getCompressedSize()); setMetaData("CRC", zipEntry.getCrc()); setMetaData("Method", zipEntry.getMethod()); setMetaData("Size", zipEntry.getSize()); setMetaData("Time", zipEntry.getTime()); setMetaData("IsDirectory", zipEntry.isDirectory()); setMetaData("Comment", zipEntry.getComment()); }