Skip to content

Commit

Permalink
Remove the shell usage of bz2, which could be a security problem if s…
Browse files Browse the repository at this point in the history
…omeone else hijacks the system's bz2 installation. Addresses https://nvd.nist.gov/vuln/detail/CVE-2023-39020
  • Loading branch information
AngledLuffa committed Aug 29, 2023
1 parent cb900f1 commit 897231b
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 97 deletions.
3 changes: 1 addition & 2 deletions src/edu/stanford/nlp/ie/crf/CRFFeatureExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
/**
* Exports CRF features for use with other programs.
* Usage: CRFFeatureExporter -prop crfClassifierPropFile -trainFile inputFile -exportFeatures outputFile
* - Output file is automatically gzipped/b2zipped if ending in gz/bz2
* - bzip2 requires that bzip2 is available via command line
* - Output file is automatically gzipped/b2zipped if ending in gz
* - Currently exports features in a format that can be read by a modified crfsgd
* (crfsgd assumes features are gzipped)
* TODO: Support other formats (like crfsuite)
Expand Down
68 changes: 0 additions & 68 deletions src/edu/stanford/nlp/io/BZip2PipedOutputStream.java

This file was deleted.

29 changes: 2 additions & 27 deletions src/edu/stanford/nlp/io/IOUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1488,7 +1488,7 @@ public static LinkedList<String[]> readCSVStrictly(String filename, int numColum
}

/**
* Get a input file stream (automatically gunzip/bunzip2 depending on file extension)
* Get a input file stream (automatically gunzip depending on file extension)
* @param filename Name of file to open
* @return Input stream that can be used to read from the file
* @throws IOException if there are exceptions opening the file
Expand All @@ -1497,15 +1497,12 @@ public static InputStream getFileInputStream(String filename) throws IOException
InputStream in = new FileInputStream(filename);
if (filename.endsWith(".gz")) {
in = new GZIPInputStream(in);
} else if (filename.endsWith(".bz2")) {
//in = new CBZip2InputStream(in);
in = getBZip2PipedInputStream(filename);
}
return in;
}

/**
* Get a output file stream (automatically gzip/bzip2 depending on file extension)
* Get a output file stream (automatically gzip depending on file extension)
* @param filename Name of file to open
* @return Output stream that can be used to write to the file
* @throws IOException if there are exceptions opening the file
Expand All @@ -1514,9 +1511,6 @@ public static OutputStream getFileOutputStream(String filename) throws IOExcepti
OutputStream out = new FileOutputStream(filename);
if (filename.endsWith(".gz")) {
out = new GZIPOutputStream(out);
} else if (filename.endsWith(".bz2")) {
//out = new CBZip2OutputStream(out);
out = getBZip2PipedOutputStream(filename);
}
return out;
}
Expand All @@ -1525,9 +1519,6 @@ public static OutputStream getFileOutputStream(String filename, boolean append)
OutputStream out = new FileOutputStream(filename, append);
if (filename.endsWith(".gz")) {
out = new GZIPOutputStream(out);
} else if (filename.endsWith(".bz2")) {
//out = new CBZip2OutputStream(out);
out = getBZip2PipedOutputStream(filename);
}
return out;
}
Expand Down Expand Up @@ -1584,22 +1575,6 @@ public static PrintWriter getPrintWriter(String filename, String encoding) throw
return new PrintWriter(new BufferedWriter(new OutputStreamWriter(out, encoding)), true);
}

public static InputStream getBZip2PipedInputStream(String filename) throws IOException {
String bzcat = System.getProperty("bzcat", "bzcat");
Runtime rt = Runtime.getRuntime();
String cmd = bzcat + " " + filename;
//log.info("getBZip2PipedInputStream: Running command: "+cmd);
Process p = rt.exec(cmd);
Writer errWriter = new BufferedWriter(new OutputStreamWriter(System.err));
StreamGobbler errGobbler = new StreamGobbler(p.getErrorStream(), errWriter);
errGobbler.start();
return p.getInputStream();
}

public static OutputStream getBZip2PipedOutputStream(String filename) throws IOException {
return new BZip2PipedOutputStream(filename);
}

private static final Pattern tab = Pattern.compile("\t");

/**
Expand Down

0 comments on commit 897231b

Please # to comment.