Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SECURITY] Fix Temporary File Information Disclosure Vulnerability #214

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions src/test/java/org/seqdoop/hadoop_bam/BAMTestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import htsjdk.samtools.SamReaderFactory;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

class BAMTestUtil {
public static File writeBamFile(int numPairs, SAMFileHeader.SortOrder sortOrder)
Expand Down Expand Up @@ -42,7 +43,7 @@ public static File writeBamFile(int numPairs, SAMFileHeader.SortOrder sortOrder)
("test-read-%03d-unplaced-unmapped", numPairs++));
}

final File bamFile = File.createTempFile("test", ".bam");
final File bamFile = Files.createTempFile("test", ".bam").toFile();
bamFile.deleteOnExit();
SAMFileHeader samHeader = samRecordSetBuilder.getHeader();
final SAMFileWriter bamWriter = new SAMFileWriterFactory()
Expand Down Expand Up @@ -75,7 +76,7 @@ public static File writeBamFileWithLargeHeader() throws IOException {
start2);
}

final File bamFile = File.createTempFile("test", ".bam");
final File bamFile = Files.createTempFile("test", ".bam").toFile();
bamFile.deleteOnExit();
SAMFileHeader samHeader = samRecordSetBuilder.getHeader();
StringBuffer sb = new StringBuffer();
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/org/seqdoop/hadoop_bam/TestBAMOutputFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void setup() throws Exception {

@Test
public void testBAMRecordWriterNoHeader() throws Exception {
final File outFile = File.createTempFile("testBAMWriter", ".bam");
final File outFile = Files.createTempFile("testBAMWriter", ".bam").toFile();
outFile.deleteOnExit();
final Path outPath = new Path(outFile.toURI());

Expand Down Expand Up @@ -120,7 +120,7 @@ public void testBAMRecordWriterNoHeader() throws Exception {

@Test
public void testBAMRecordWriterWithHeader() throws Exception {
final File outFile = File.createTempFile("testBAMWriter", ".bam");
final File outFile = Files.createTempFile("testBAMWriter", ".bam").toFile();
outFile.deleteOnExit();
final Path outPath = new Path(outFile.toURI());

Expand Down Expand Up @@ -150,7 +150,7 @@ public void testBAMRecordWriterWithHeader() throws Exception {
@Test
public void testBAMOutput() throws Exception {
final Path outputPath = doMapReduce(testBAMFileName);
final File outFile = File.createTempFile("testBAMWriter", ".bam");
final File outFile = Files.createTempFile("testBAMWriter", ".bam").toFile();
outFile.deleteOnExit();
SAMFileMerger.mergeParts(outputPath.toUri().toString(), outFile.toURI().toString(),
SAMFormat.BAM, samFileHeader);
Expand All @@ -164,7 +164,7 @@ public void testEmptyBAM() throws Exception {
SAMFileHeader.SortOrder.coordinate).toURI().toString();
conf.setBoolean(BAMOutputFormat.WRITE_SPLITTING_BAI, true);
final Path outputPath = doMapReduce(bam);
final File outFile = File.createTempFile("testBAMWriter", ".bam");
final File outFile = Files.createTempFile("testBAMWriter", ".bam").toFile();
outFile.deleteOnExit();
SAMFileMerger.mergeParts(outputPath.toUri().toString(), outFile.toURI().toString(),
SAMFormat.BAM, new SAMRecordSetBuilder(true, SAMFileHeader.SortOrder.coordinate).getHeader());
Expand Down Expand Up @@ -194,7 +194,7 @@ public void testBAMWithSplittingBai() throws Exception {
recordsAtSplits.addAll(getRecordsAtSplits(bamFile, index));
}

final File outFile = File.createTempFile("testBAMWriter", ".bam");
final File outFile = Files.createTempFile("testBAMWriter", ".bam").toFile();
//outFile.deleteOnExit();
SAMFileMerger.mergeParts(outputPath.toUri().toString(), outFile.toURI().toString(),
SAMFormat.BAM,
Expand Down Expand Up @@ -231,7 +231,7 @@ public void testBAMRoundTrip() throws Exception {
Path outputPath = doMapReduce(testBAMFileName);

// merge the parts, and write to a temp file
final File outFile = File.createTempFile("testBAMWriter", ".bam");
final File outFile = Files.createTempFile("testBAMWriter", ".bam").toFile();
outFile.deleteOnExit();
SAMFileMerger.mergeParts(outputPath.toUri().toString(), outFile.toURI().toString(),
SAMFormat.BAM, samFileHeader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void setup() throws Exception {

@Test
public void testCRAMRecordWriterNoHeader() throws Exception {
final File outFile = File.createTempFile("testCRAMWriter", ".cram");
final File outFile = Files.createTempFile("testCRAMWriter", ".cram").toFile();
outFile.deleteOnExit();
final Path outPath = new Path(outFile.toURI());

Expand Down Expand Up @@ -125,7 +125,7 @@ public void testCRAMRecordWriterNoHeader() throws Exception {

@Test
public void testCRAMRecordWriterWithHeader() throws Exception {
final File outFile = File.createTempFile("testCRAMWriter", ".cram");
final File outFile = Files.createTempFile("testCRAMWriter", ".cram").toFile();
outFile.deleteOnExit();
final Path outPath = new Path(outFile.toURI());

Expand Down Expand Up @@ -155,7 +155,7 @@ public void testCRAMRecordWriterWithHeader() throws Exception {
@Test
public void testCRAMOutput() throws Exception {
final Path outputPath = doMapReduce(testCRAMFileName);
final File outFile = File.createTempFile("testCRAMWriter", ".cram");
final File outFile = Files.createTempFile("testCRAMWriter", ".cram").toFile();
outFile.deleteOnExit();
SAMFileMerger.mergeParts(outputPath.toUri().toString(), outFile.toURI().toString(),
SAMFormat.CRAM, samFileHeader);
Expand All @@ -171,7 +171,7 @@ public void testCRAMRoundTrip() throws Exception {
Path outputPath = doMapReduce(testCRAMFileName);

// merge the parts, and write to a temp file
final File outFile = File.createTempFile("testCRAMWriter", ".cram");
final File outFile = Files.createTempFile("testCRAMWriter", ".cram").toFile();
outFile.deleteOnExit();
SAMFileMerger.mergeParts(outputPath.toUri().toString(), outFile.toURI().toString(),
SAMFormat.CRAM, samFileHeader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.FileOutputStream;
Expand Down Expand Up @@ -137,8 +138,8 @@ public class TestFastqInputFormat
@Before
public void setup() throws IOException
{
tempFastq = File.createTempFile("test_fastq_input_format", "fastq");
tempGz = File.createTempFile("test_fastq_input_format", ".gz");
tempFastq = Files.createTempFile("test_fastq_input_format", "fastq").toFile();
tempGz = Files.createTempFile("test_fastq_input_format", ".gz").toFile();
conf = new JobConf();
key = new Text();
fragment = new SequencedFragment();
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/org/seqdoop/hadoop_bam/TestQseqInputFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.FileOutputStream;
Expand Down Expand Up @@ -92,8 +93,8 @@ public class TestQseqInputFormat
@Before
public void setup() throws IOException
{
tempQseq = File.createTempFile("test_qseq_input_format", "qseq");
tempGz = File.createTempFile("test_qseq_input_format", ".gz");
tempQseq = Files.createTempFile("test_qseq_input_format", "qseq").toFile();
tempGz = Files.createTempFile("test_qseq_input_format", ".gz").toFile();
conf = new JobConf();
key = new Text();
fragment = new SequencedFragment();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files;
import java.util.*;

import htsjdk.samtools.seekablestream.SeekableFileStream;
Expand Down Expand Up @@ -54,7 +55,7 @@ public class TestVCFOutputFormat {

@Before
public void setup() throws IOException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
test_vcf_output = File.createTempFile("test_vcf_output", "");
test_vcf_output = Files.createTempFile("test_vcf_output", "").toFile();
test_vcf_output.delete();
writable = new VariantContextWritable();
Configuration conf = new Configuration();
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/seqdoop/hadoop_bam/TestVCFRoundTrip.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -199,8 +200,7 @@ public void testRoundTripWithMerge() throws Exception {
// merge the output
VCFHeader vcfHeader = VCFHeaderReader.readHeaderFrom(new SeekableFileStream(new
File(testVCFFileName)));
final File outFile = File.createTempFile("testVCFWriter",
testVCFFileName.substring(testVCFFileName.lastIndexOf(".")));
final File outFile = Files.createTempFile("testVCFWriter", testVCFFileName.substring(testVCFFileName.lastIndexOf("."))).toFile();
outFile.deleteOnExit();
VCFFileMerger.mergeParts(outputPath.toUri().toString(), outFile.toURI().toString(),
vcfHeader);
Expand Down Expand Up @@ -256,7 +256,7 @@ private static VCFFileReader parseVcf(File vcf) throws IOException {
File actualVcf;
// work around TribbleIndexedFeatureReader not reading header from .bgz files
if (vcf.getName().endsWith(".bgz")) {
actualVcf = File.createTempFile(vcf.getName(), ".gz");
actualVcf = Files.createTempFile(vcf.getName(), ".gz").toFile();
actualVcf.deleteOnExit();
Files.copy(vcf, actualVcf);
} else {
Expand Down