34
34
35
35
public class CommonsCompressHandler {
36
36
37
- static void commonsCompressArchiveInputStream (InputStream inputStream ) throws ArchiveException {
38
- new ArArchiveInputStream (inputStream ); // $ hasTaintFlow="inputStream"
39
- new ArjArchiveInputStream (inputStream ); // $ hasTaintFlow="inputStream"
40
- new CpioArchiveInputStream (inputStream ); // $ hasTaintFlow="inputStream"
41
- new JarArchiveInputStream (inputStream ); // $ hasTaintFlow="inputStream"
42
- new ZipArchiveInputStream (inputStream ); // $ hasTaintFlow="inputStream"
43
- }
44
-
45
37
public static void commonsCompressorInputStream (InputStream inputStream ) throws IOException {
46
38
BufferedInputStream in = new BufferedInputStream (inputStream );
47
39
OutputStream out = Files .newOutputStream (Path .of ("tmpfile" ));
48
- GzipCompressorInputStream gzIn = new GzipCompressorInputStream (in ); // $ hasTaintFlow="in"
49
- // for testing
50
- new BrotliCompressorInputStream (in ); // $ hasTaintFlow="in"
51
- new BZip2CompressorInputStream (in ); // $ hasTaintFlow="in"
52
- new DeflateCompressorInputStream (in ); // $ hasTaintFlow="in"
53
- new Deflate64CompressorInputStream (in ); // $ hasTaintFlow="in"
54
- new BlockLZ4CompressorInputStream (in ); // $ hasTaintFlow="in"
55
- new LZMACompressorInputStream (in ); // $ hasTaintFlow="in"
56
- new Pack200CompressorInputStream (in ); // $ hasTaintFlow="in"
57
- new SnappyCompressorInputStream (in ); // $ hasTaintFlow="in"
58
- new XZCompressorInputStream (in ); // $ hasTaintFlow="in"
59
- new ZCompressorInputStream (in ); // $ hasTaintFlow="in"
60
- new ZstdCompressorInputStream (in ); // $ hasTaintFlow="in"
40
+ GzipCompressorInputStream gzIn = new GzipCompressorInputStream (in );
41
+ // Also, the `new GzipCompressorInputStream(in)` can be the following:
42
+ // new BrotliCompressorInputStream(in);
43
+ // new BZip2CompressorInputStream(in);
44
+ // new DeflateCompressorInputStream(in);
45
+ // new Deflate64CompressorInputStream(in);
46
+ // new BlockLZ4CompressorInputStream(in);
47
+ // new LZMACompressorInputStream(in);
48
+ // new Pack200CompressorInputStream(in);
49
+ // new SnappyCompressorInputStream(in);
50
+ // new XZCompressorInputStream(in);
51
+ // new ZCompressorInputStream(in);
52
+ // new ZstdCompressorInputStream(in);
53
+
54
+ int buffersize = 4096 ;
55
+ final byte [] buffer = new byte [buffersize ];
56
+ int n = 0 ;
57
+ while (-1 != (n = gzIn .read (buffer ))) { // $ hasTaintFlow="gzIn"
58
+ out .write (buffer , 0 , n );
59
+ }
60
+ out .close ();
61
+ gzIn .close ();
61
62
}
62
63
63
- static void commonsCompressArchiveInputStream2 (InputStream inputStream ) {
64
+ static void commonsCompressArchiveInputStream (InputStream inputStream ) {
64
65
byte [] readBuffer = new byte [4096 ];
65
- try (org .apache .commons .compress .archivers .zip .ZipArchiveInputStream zipInputStream =
66
- new org .apache .commons .compress .archivers .zip .ZipArchiveInputStream (inputStream )) { // $ hasTaintFlow="inputStream"
66
+
67
+ // Also, the `new ZipArchiveInputStream(inputStream)` can be the following:
68
+ // new ArArchiveInputStream(inputStream);
69
+ // new ArjArchiveInputStream(inputStream);
70
+ // new CpioArchiveInputStream(inputStream);
71
+ // new JarArchiveInputStream(inputStream);
72
+ // new ZipArchiveInputStream(inputStream);
73
+
74
+ try (ZipArchiveInputStream zipInputStream =
75
+ new ZipArchiveInputStream (inputStream )) {
67
76
ArchiveEntry entry = null ;
68
77
while ((entry = zipInputStream .getNextEntry ()) != null ) {
69
78
if (!zipInputStream .canReadEntryData (entry )) {
@@ -72,7 +81,7 @@ static void commonsCompressArchiveInputStream2(InputStream inputStream) {
72
81
File f = new File ("tmpfile" );
73
82
try (OutputStream outputStream = new FileOutputStream (f )) {
74
83
int readLen ;
75
- while ((readLen = zipInputStream .read (readBuffer )) != -1 ) {
84
+ while ((readLen = zipInputStream .read (readBuffer )) != -1 ) { // $ hasTaintFlow="zipInputStream"
76
85
outputStream .write (readBuffer , 0 , readLen );
77
86
}
78
87
}
0 commit comments