static void throwZipException(String filename, long fileSize, String entryName, long localHeaderRelOffset, String msg, int magic) throws ZipException { final String hexString = Integer.toHexString(magic); throw new ZipException("file name:" + filename + ", file size" + fileSize + ", entry name:" + entryName + ", entry localHeaderRelOffset:" + localHeaderRelOffset + ", " + msg + " signature not found; was " + hexString); }
/** * Populate data from this array as if it was in local file data. * @param data an array of bytes * @param offset the start offset * @param length the number of bytes in the array from offset * * @throws ZipException on error */ public void parseFromLocalFileData(byte[] data, int offset, int length) throws ZipException { if (length != 0) { throw new ZipException("JarMarker doesn't expect any data"); } } }
static void throwZipException(String msg, int magic) throws ZipException { final String hexString = String.format("0x%08x", magic); throw new ZipException(msg + " signature not found; was " + hexString); }
/** * Populate data from this array as if it was in local file data. * @param data an array of bytes * @param offset the start offset * @param length the number of bytes in the array from offset * * @throws ZipException on error */ @Override public void parseFromLocalFileData(final byte[] data, final int offset, final int length) throws ZipException { if (length != 0) { throw new ZipException("JarMarker doesn't expect any data"); } }
/** * Populate data from this array as if it was in local file data. * @param data an array of bytes * @param offset the start offset * @param length the number of bytes in the array from offset * * @throws ZipException on error */ public void parseFromLocalFileData(byte[] data, int offset, int length) throws ZipException { if (length != 0) { throw new ZipException("JarMarker doesn't expect any data"); } } }
private void write() throws IOException, ZipException { try { int inflated; while ((inflated = inf.inflate(buf)) > 0) { out.write(buf, 0, inflated); } } catch (DataFormatException e) { throw new ZipException(); } }
@Override public void parseFromLocalFileData(final byte[] buffer, final int offset, final int length) throws ZipException { if (length < 5) { throw new ZipException("UniCode path extra data must have at least 5 bytes."); } final int version = buffer[offset]; if (version != 0x01) { throw new ZipException("Unsupported version [" + version + "] for UniCode path extra data."); } nameCRC32 = ZipLong.getValue(buffer, offset + 1); unicodeName = new byte[length - 5]; System.arraycopy(buffer, offset + 5, unicodeName, 0, length - 5); data = null; }
/** {@inheritDoc} */ public void parseFromLocalFileData(final byte[] buffer, final int offset, final int length) throws ZipException { if (length < 5) { throw new ZipException("UniCode path extra data must have at least" + " 5 bytes."); } final int version = buffer[offset]; if (version != 0x01) { throw new ZipException("Unsupported version [" + version + "] for UniCode path extra data."); } nameCRC32 = ZipLong.getValue(buffer, offset + 1); unicodeName = new byte[length - 5]; System.arraycopy(buffer, offset + 5, unicodeName, 0, length - 5); data = null; }
/** * Searches for the and positions the stream at the start of the * "End of central dir record". */ private void positionAtEndOfCentralDirectoryRecord() throws IOException { final boolean found = tryToLocateSignature(MIN_EOCD_SIZE, MAX_EOCD_SIZE, ZipOutputStream.EOCD_SIG); if (!found) { throw new ZipException("archive is not a ZIP archive"); } }
/** * Searches for the and positions the stream at the start of the * "End of central dir record". */ private void positionAtEndOfCentralDirectoryRecord() throws IOException { boolean found = tryToLocateSignature(MIN_EOCD_SIZE, MAX_EOCD_SIZE, ZipOutputStream.EOCD_SIG); if (!found) { throw new ZipException("archive is not a ZIP archive"); } }
/** * Searches for the and positions the stream at the start of the * "End of central dir record". */ private void positionAtEndOfCentralDirectoryRecord() throws IOException { boolean found = tryToLocateSignature(MIN_EOCD_SIZE, MAX_EOCD_SIZE, ZipOutputStream.EOCD_SIG); if (!found) { throw new ZipException("archive is not a ZIP archive"); } }
@Override public void parseFromCentralDirectoryData(byte[] buffer, int offset, int length) throws ZipException { if (length < BASE_SIZE) { throw new ZipException("Too short content for ResourceAlignmentExtraField (0xa11e): " + length); } int alignmentValue = ZipShort.getValue(buffer, offset); this.alignment = (short) (alignmentValue & (ALLOW_METHOD_MESSAGE_CHANGE_FLAG - 1)); this.allowMethodChange = (alignmentValue & ALLOW_METHOD_MESSAGE_CHANGE_FLAG) != 0; } }
/** * Searches for the and positions the stream at the start of the * "End of central dir record". */ private void positionAtEndOfCentralDirectoryRecord() throws IOException { final boolean found = tryToLocateSignature(MIN_EOCD_SIZE, MAX_EOCD_SIZE, ZipArchiveOutputStream.EOCD_SIG); if (!found) { throw new ZipException("archive is not a ZIP archive"); } }
static void throwZipException(String msg, int magic) throws ZipException { final String hexString = IntegralToString.intToHexString(magic, true, 8); throw new ZipException(msg + " signature not found; was " + hexString); }
/** * Writes data for the current entry to the underlying stream. * * @throws IOException * If an error occurs writing to the stream */ @Override public void write(byte[] buffer, int offset, int byteCount) throws IOException { Arrays.checkOffsetAndCount(buffer.length, offset, byteCount); if (currentEntry == null) { throw new ZipException("No active entry"); } /*final long totalBytes = crc.tbytes + byteCount; if ((totalBytes > Zip64.MAX_ZIP_ENTRY_AND_ARCHIVE_SIZE) && !currentEntryNeedsZip64) { throw new IOException("Zip entry size (" + totalBytes + " bytes) cannot be represented in the zip format (needs Zip64)." + " Set the entry length using ZipEntry#setLength to use Zip64 where necessary."); }*/ if (currentEntry.getMethod() == STORED) { out.write(buffer, offset, byteCount); } else { out.write(buffer, offset, byteCount); } // crc.update(buffer, offset, byteCount); } private void checkOpen() throws IOException {
public Callables loadProceduresFromDir( File root ) throws IOException, KernelException { if ( root == null || !root.exists() ) { return Callables.empty(); } Callables out = new Callables(); File[] dirListing = root.listFiles( ( dir, name ) -> name.endsWith( ".jar" ) ); if ( dirListing == null ) { return Callables.empty(); } if ( !allJarFilesAreValidZipFiles( Stream.of( dirListing ) ) ) { throw new ZipException( "Some jar procedure files are invalid, see log for details." ); } URL[] jarFilesURLs = Stream.of( dirListing ).map( this::toURL ).toArray( URL[]::new ); URLClassLoader loader = new URLClassLoader( jarFilesURLs, this.getClass().getClassLoader() ); for ( URL jarFile : jarFilesURLs ) { loadProcedures( jarFile, loader, out ); } return out; }
private void readAndVerifyDataDescriptor(int inB, int out) throws IOException { if (hasDD) { Streams.readFully(in, hdrBuf, 0, EXTHDR); int sig = Memory.peekInt(hdrBuf, 0, ByteOrder.LITTLE_ENDIAN); if (sig != (int) EXTSIG) { throw new ZipException(String.format("unknown format (EXTSIG=%x)", sig)); } currentEntry.crc = ((long) Memory.peekInt(hdrBuf, EXTCRC, ByteOrder.LITTLE_ENDIAN)) & 0xffffffffL; currentEntry.compressedSize = ((long) Memory.peekInt(hdrBuf, EXTSIZ, ByteOrder.LITTLE_ENDIAN)) & 0xffffffffL; currentEntry.size = ((long) Memory.peekInt(hdrBuf, EXTLEN, ByteOrder.LITTLE_ENDIAN)) & 0xffffffffL; } if (currentEntry.crc != crc.getValue()) { throw new ZipException("CRC mismatch"); } if (currentEntry.compressedSize != inB || currentEntry.size != out) { throw new ZipException("Size mismatch"); } }
throw new ZipException("No entries");
centralDirOffset = ((long) it.readInt()) & 0xffffffffL; if (numEntries != totalNumEntries || diskNumber != 0 || diskWithCentralDir != 0) { throw new ZipException("Spanned archives not supported");
int gpbf = it.readShort() & 0xffff; if ((gpbf & TinkerZipFile.GPBF_UNSUPPORTED_MASK) != 0) { throw new ZipException("Invalid General Purpose Bit Flag: " + gpbf); Streams.readFully(cdStream, nameBytes, 0, nameBytes.length); if (containsNulByte(nameBytes)) { throw new ZipException("Filename contains NUL byte: " + Arrays.toString(nameBytes));