Skip to content

Commit 897231b

Browse files
committed
Remove the shell usage of bz2, which could be a security problem if someone else hijacks the system's bz2 installation. Addresses https://nvd.nist.gov/vuln/detail/CVE-2023-39020
1 parent cb900f1 commit 897231b

File tree

3 files changed

+3
-97
lines changed

3 files changed

+3
-97
lines changed

src/edu/stanford/nlp/ie/crf/CRFFeatureExporter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
/**
1919
* Exports CRF features for use with other programs.
2020
* Usage: CRFFeatureExporter -prop crfClassifierPropFile -trainFile inputFile -exportFeatures outputFile
21-
* - Output file is automatically gzipped/b2zipped if ending in gz/bz2
22-
* - bzip2 requires that bzip2 is available via command line
21+
* - Output file is automatically gzipped/b2zipped if ending in gz
2322
* - Currently exports features in a format that can be read by a modified crfsgd
2423
* (crfsgd assumes features are gzipped)
2524
* TODO: Support other formats (like crfsuite)

src/edu/stanford/nlp/io/BZip2PipedOutputStream.java

Lines changed: 0 additions & 68 deletions
This file was deleted.

src/edu/stanford/nlp/io/IOUtils.java

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,7 +1488,7 @@ public static LinkedList<String[]> readCSVStrictly(String filename, int numColum
14881488
}
14891489

14901490
/**
1491-
* Get a input file stream (automatically gunzip/bunzip2 depending on file extension)
1491+
* Get a input file stream (automatically gunzip depending on file extension)
14921492
* @param filename Name of file to open
14931493
* @return Input stream that can be used to read from the file
14941494
* @throws IOException if there are exceptions opening the file
@@ -1497,15 +1497,12 @@ public static InputStream getFileInputStream(String filename) throws IOException
14971497
InputStream in = new FileInputStream(filename);
14981498
if (filename.endsWith(".gz")) {
14991499
in = new GZIPInputStream(in);
1500-
} else if (filename.endsWith(".bz2")) {
1501-
//in = new CBZip2InputStream(in);
1502-
in = getBZip2PipedInputStream(filename);
15031500
}
15041501
return in;
15051502
}
15061503

15071504
/**
1508-
* Get a output file stream (automatically gzip/bzip2 depending on file extension)
1505+
* Get a output file stream (automatically gzip depending on file extension)
15091506
* @param filename Name of file to open
15101507
* @return Output stream that can be used to write to the file
15111508
* @throws IOException if there are exceptions opening the file
@@ -1514,9 +1511,6 @@ public static OutputStream getFileOutputStream(String filename) throws IOExcepti
15141511
OutputStream out = new FileOutputStream(filename);
15151512
if (filename.endsWith(".gz")) {
15161513
out = new GZIPOutputStream(out);
1517-
} else if (filename.endsWith(".bz2")) {
1518-
//out = new CBZip2OutputStream(out);
1519-
out = getBZip2PipedOutputStream(filename);
15201514
}
15211515
return out;
15221516
}
@@ -1525,9 +1519,6 @@ public static OutputStream getFileOutputStream(String filename, boolean append)
15251519
OutputStream out = new FileOutputStream(filename, append);
15261520
if (filename.endsWith(".gz")) {
15271521
out = new GZIPOutputStream(out);
1528-
} else if (filename.endsWith(".bz2")) {
1529-
//out = new CBZip2OutputStream(out);
1530-
out = getBZip2PipedOutputStream(filename);
15311522
}
15321523
return out;
15331524
}
@@ -1584,22 +1575,6 @@ public static PrintWriter getPrintWriter(String filename, String encoding) throw
15841575
return new PrintWriter(new BufferedWriter(new OutputStreamWriter(out, encoding)), true);
15851576
}
15861577

1587-
public static InputStream getBZip2PipedInputStream(String filename) throws IOException {
1588-
String bzcat = System.getProperty("bzcat", "bzcat");
1589-
Runtime rt = Runtime.getRuntime();
1590-
String cmd = bzcat + " " + filename;
1591-
//log.info("getBZip2PipedInputStream: Running command: "+cmd);
1592-
Process p = rt.exec(cmd);
1593-
Writer errWriter = new BufferedWriter(new OutputStreamWriter(System.err));
1594-
StreamGobbler errGobbler = new StreamGobbler(p.getErrorStream(), errWriter);
1595-
errGobbler.start();
1596-
return p.getInputStream();
1597-
}
1598-
1599-
public static OutputStream getBZip2PipedOutputStream(String filename) throws IOException {
1600-
return new BZip2PipedOutputStream(filename);
1601-
}
1602-
16031578
private static final Pattern tab = Pattern.compile("\t");
16041579

16051580
/**

0 commit comments

Comments
 (0)