src/main/java/org/edgegallery/appstore/domain/model/releases/PackageChecker.java
public final void unzip(String fileName) throws IOException {
        ZipArchiveEntry entry;
        int entries = 0;
        long total = 0;
        byte[] data = new byte[BUFFER];
        List<File> tempFiles = new ArrayList<>();
        try (ZipArchiveInputStream zis = new ZipArchiveInputStream(new FileInputStream(new File(fileName)))) {
            while ((entry = zis.getNextZipEntry()) != null) {
                int count;
                // Write the files to the disk, but ensure that the entryName is valid,
                // and that the file is not insanely big
                String name = sanitzeFileName(entry.getName(), getDir() + File.separator + "temp");
                File f = new File(name);
                tempFiles.add(f);
                if (isDir(entry, f)) {
                    continue;
                }
                FileOutputStream fos = FileUtils.openOutputStream(f);
                try (BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER)) {
                    while (total <= TOOBIG && (count = zis.read(data, 0, BUFFER)) != -1) {
                        dest.write(data, 0, count);
                        total += count;
                    }
                    dest.flush();
                }
                entries++;
                if (entries > TOOMANY) {
                    throw new IllegalRequestException("Too many files to unzip.",
                        ResponseConst.RET_UNZIP_TOO_MANY_FILES, TOOMANY);
                }
                if (total > TOOBIG) {
                    throw new IllegalRequestException("File being unzipped is too big",
                        ResponseConst.RET_FILE_TOO_BIG, entry.getName(), TOOBIG);
                }
            }
        } catch (IOException e) {
            throw new IllegalRequestException("unzip csar with exception.", ResponseConst.RET_DECOMPRESS_FAILED);
        } finally {
            deleteTempFiles(tempFiles);
        }
    }
/**
     * Prevent bomb attacks.
     *
     * @param fileName file name.
     * @throws java.io.IOException throw IOException
     */
Prevent bomb attacks.
@param fileName file name.
Prevent bomb attacks . @param fileName file name .
public final void unzip(String fileName) throws IOException {
        ZipArchiveEntry entry;
        int entries = 0;
        long total = 0;
        byte[] data = new byte[BUFFER];
        List<File> tempFiles = new ArrayList<>();
        try (ZipArchiveInputStream zis = new ZipArchiveInputStream(new FileInputStream(new File(fileName)))) {
            while ((entry = zis.getNextZipEntry()) != null) {
                int count;
                String name = sanitzeFileName(entry.getName(), getDir() + File.separator + "temp");
                File f = new File(name);
                tempFiles.add(f);
                if (isDir(entry, f)) {
                    continue;
                }
                FileOutputStream fos = FileUtils.openOutputStream(f);
                try (BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER)) {
                    while (total <= TOOBIG && (count = zis.read(data, 0, BUFFER)) != -1) {
                        dest.write(data, 0, count);
                        total += count;
                    }
                    dest.flush();
                }
                entries++;
                if (entries > TOOMANY) {
                    throw new IllegalRequestException("Too many files to unzip.",
                        ResponseConst.RET_UNZIP_TOO_MANY_FILES, TOOMANY);
                }
                if (total > TOOBIG) {
                    throw new IllegalRequestException("File being unzipped is too big",
                        ResponseConst.RET_FILE_TOO_BIG, entry.getName(), TOOBIG);
                }
            }
        } catch (IOException e) {
            throw new IllegalRequestException("unzip csar with exception.", ResponseConst.RET_DECOMPRESS_FAILED);
        } finally {
            deleteTempFiles(tempFiles);
        }
    }
public final void unzip ( String fileName ) throws IOException { ZipArchiveEntry entry ; int entries = 0 ; long total = 0 ; byte [ ] data = new byte [ BUFFER ] ; List < File > tempFiles = new ArrayList < > ( ) ; try ( ZipArchiveInputStream zis = new ZipArchiveInputStream ( new FileInputStream ( new File ( fileName ) ) ) ) { while ( ( entry = zis . getNextZipEntry ( ) ) != null ) { int count ; String name = sanitzeFileName ( entry . getName ( ) , getDir ( ) + File . separator + "temp" ) ; File f = new File ( name ) ; tempFiles . add ( f ) ; if ( isDir ( entry , f ) ) { continue ; } FileOutputStream fos = FileUtils . openOutputStream ( f ) ; try ( BufferedOutputStream dest = new BufferedOutputStream ( fos , BUFFER ) ) { while ( total <= TOOBIG && ( count = zis . read ( data , 0 , BUFFER ) ) != - 1 ) { dest . write ( data , 0 , count ) ; total += count ; } dest . flush ( ) ; } entries ++ ; if ( entries > TOOMANY ) { throw new IllegalRequestException ( "Too many files to unzip." , ResponseConst . RET_UNZIP_TOO_MANY_FILES , TOOMANY ) ; } if ( total > TOOBIG ) { throw new IllegalRequestException ( "File being unzipped is too big" , ResponseConst . RET_FILE_TOO_BIG , entry . getName ( ) , TOOBIG ) ; } } } catch ( IOException e ) { throw new IllegalRequestException ( "unzip csar with exception." , ResponseConst . RET_DECOMPRESS_FAILED ) ; } finally { deleteTempFiles ( tempFiles ) ; } }
Prevent bomb attacks.
Prevent bomb attacks .
// Write the files to the disk, but ensure that the entryName is valid, // and that the file is not insanely big