JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.

If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.

If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.

CodeSonar® 9.2p0 CONFIDENTIAL CodeSecure Inc
Java


JAVA.STRUCT.ARCHIVE.EZF : Empty zip File Archived (Java)

要旨

An empty zip entry is added to a zip file.

The programmatic construction of zip or jar archives might be incorrect, when for instance empty entries get added to an archive. This checker looks for inconsistent operation in the creation of such archives.

プロパティ

クラス名 Empty zip File Archived (Java)
日本語クラス名 Empty zip File Archived (Java)
クラス分類 信頼性 (reliability)
ニーモニック JAVA.STRUCT.ARCHIVE.EZF
カテゴリー
CWE CWE:909 Missing Initialization of Resource
対応言語 Available for Java and Kotlin.
有効/無効設定 このワーニングクラスのチェックはデフォルトで有効になっています。チェックを無効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += discard class="Empty zip File Archived (Java)"

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.jar.JarOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class ZipCreator {
  public static void main(String[] args) {
    try (ZipOutputStream jos = new JarOutputStream(new FileOutputStream(new File("archive.jar")))) {
      ZipEntry entry = new ZipEntry("doc.txt");
      jos.putNextEntry(entry);
      jos.closeEntry();  // Empty jar File Archived (Java) warning issued here 
    }
    catch (IOException e) {
      e.printStackTrace();
    }

    try (ZipOutputStream jos = new ZipOutputStream(new FileOutputStream(new File("archive.jar")))) {
      ZipEntry entry = new ZipEntry("doc.txt");
      jos.putNextEntry(entry);
      jos.closeEntry();  // Empty zip File Archived (Java) warning issued here 
    }
    catch (IOException e) {
      e.printStackTrace();
    }

    try (JarOutputStream jos = new JarOutputStream(new FileOutputStream(new File("archive.jar")));
         FileInputStream fis = new FileInputStream(new File("test.txt"))) {

      ZipEntry entry = new ZipEntry("doc.txt");
      jos.putNextEntry(entry);

      byte[] buf = new byte[1024];
      int len;
      while((len = fis.read(buf)) > 0)
        jos.write(buf, 0, len);

      jos.closeEntry();
    }
    catch (IOException e) {
      e.printStackTrace();
    }
  }
}

解決法

Check if, for instance, empty entries are added to a jar or zip archive.

関連のある設定ファイルパラメータ

設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。

 

To report problems with this documentation, please visit https://support.codesecure.com/.