3434
3535public class CommonsCompressHandler {
3636
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-
4537 public static void commonsCompressorInputStream (InputStream inputStream ) throws IOException {
4638 BufferedInputStream in = new BufferedInputStream (inputStream );
4739 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 ();
6162 }
6263
63- static void commonsCompressArchiveInputStream2 (InputStream inputStream ) {
64+ static void commonsCompressArchiveInputStream (InputStream inputStream ) {
6465 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 )) {
6776 ArchiveEntry entry = null ;
6877 while ((entry = zipInputStream .getNextEntry ()) != null ) {
6978 if (!zipInputStream .canReadEntryData (entry )) {
@@ -72,7 +81,7 @@ static void commonsCompressArchiveInputStream2(InputStream inputStream) {
7281 File f = new File ("tmpfile" );
7382 try (OutputStream outputStream = new FileOutputStream (f )) {
7483 int readLen ;
75- while ((readLen = zipInputStream .read (readBuffer )) != -1 ) {
84+ while ((readLen = zipInputStream .read (readBuffer )) != -1 ) { // $ hasTaintFlow="zipInputStream"
7685 outputStream .write (readBuffer , 0 , readLen );
7786 }
7887 }
0 commit comments