Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1994,7 +1994,7 @@
{
"ruleKey": "S5042",
"hasTruePositives": true,
"falseNegatives": 0,
"falseNegatives": 8,
"falsePositives": 0
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"ruleKey": "S5042",
"hasTruePositives": true,
"falseNegatives": 0,
"falseNegatives": 8,
"falsePositives": 0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Enumeration;
import java.util.List;
import java.util.Optional;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;
import org.apache.commons.compress.archivers.sevenz.SevenZArchiveEntry;
import org.apache.commons.compress.archivers.sevenz.SevenZFile;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.apache.commons.compress.archivers.tar.TarFile;

public class ZipEntryCheck {

Expand Down Expand Up @@ -93,3 +101,61 @@ public String compliant() throws java.lang.Exception {
}

}

class TarUtilities {
private TarUtilities() {
/* This utility class should not be instantiated */
}

public static List<TarArchiveEntry> getAllEntries(TarFile file) {
return file.getEntries(); // Noncompliant {{Make sure that expanding this archive file is safe here.}}
// ^^^^^^^^^^
}

public static Optional<TarArchiveEntry> getNext(TarArchiveInputStream stream) throws IOException {
return Optional.of(stream.getNextEntry()); // Noncompliant {{Make sure that expanding this archive file is safe here.}}
// ^^^^^^^^^^^^
}

public static long getEntrySize(TarArchiveEntry entry) {
return entry.getSize(); // Noncompliant {{Make sure that expanding this archive file is safe here.}}
// ^^^^^^^
}
}

class SevenZUtilities {
private SevenZUtilities() {
/* This utility class should not be instantiated */
}

public static Iterable<SevenZArchiveEntry> getAllEntries(SevenZFile file) {
return file.getEntries(); // Noncompliant {{Make sure that expanding this archive file is safe here.}}
// ^^^^^^^^^^
}

public static long getEntrySize(SevenZArchiveEntry entry) {
return entry.getSize(); // Noncompliant {{Make sure that expanding this archive file is safe here.}}
// ^^^^^^^
}
}

class ApacheCommonsZipUtilities {
private ApacheCommonsZipUtilities() {
/* This utility class should not be instantiated */
}

public static Enumeration<org.apache.commons.compress.archivers.zip.ZipArchiveEntry> getAllEntries(org.apache.commons.compress.archivers.zip.ZipFile file) {
return file.getEntries(); // Noncompliant {{Make sure that expanding this archive file is safe here.}}
// ^^^^^^^^^^
}

public static Optional<org.apache.commons.compress.archivers.zip.ZipArchiveEntry> getNext(org.apache.commons.compress.archivers.zip.ZipArchiveInputStream stream) throws IOException {
return Optional.of(stream.getNextEntry()); // Noncompliant {{Make sure that expanding this archive file is safe here.}}
// ^^^^^^^^^^^^
}

public static long getEntrySize(org.apache.commons.compress.archivers.zip.ZipArchiveEntry entry) {
return entry.getSize(); // Noncompliant {{Make sure that expanding this archive file is safe here.}}
// ^^^^^^^
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,19 @@ public class ZipEntryCheck extends IssuableSubscriptionVisitor {
.addWithoutParametersMatcher()
.build(),
MethodMatchers.create()
.ofSubTypes("java.util.zip.ZipEntry")
.ofSubTypes("org.apache.commons.compress.archivers.tar.TarFile",
"org.apache.commons.compress.archivers.sevenz.SevenZFile",
"org.apache.commons.compress.archivers.zip.ZipFile")
.names("getEntries")
.addWithoutParametersMatcher()
.build(),
MethodMatchers.create()
.ofSubTypes("java.util.zip.ZipEntry", "org.apache.commons.compress.archivers.ArchiveEntry")
.names("getSize")
.addWithoutParametersMatcher()
.build(),
MethodMatchers.create()
.ofSubTypes("java.util.zip.ZipInputStream")
.ofSubTypes("java.util.zip.ZipInputStream", "org.apache.commons.compress.archivers.ArchiveInputStream")
.names("getNextEntry")
.addWithoutParametersMatcher()
.build()
Expand Down
Loading