From cf6e166b24d1534ff38e30f7d685242de2bc8b59 Mon Sep 17 00:00:00 2001 From: Rob Davies Date: Thu, 15 Aug 2024 14:45:23 +0100 Subject: [PATCH] Fix hts_hfile() for compressed text_format files SAM and VCF files opened for write both start with htsFile::format.format set to text_format, and then update it after writing the header. This means it's possible to open a text_format file with compression, so hts_hfile() needs to handle it in the same way as sam and vcf. Noticed when hts_set_opt(fpout, HTS_OPT_BLOCK_SIZE, BAM_BLOCK_SIZE) failed in samtools sort in the case where fpout was a compressed sam file. At this point fpout was a text_file, so the wrong pointer was passed to hfile_set_blksize(), which luckily bailed out and returned -1 before doing any damage to the incorrectly passed-in structure. --- hts.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hts.c b/hts.c index 42be3f21f..55af35cd4 100644 --- a/hts.c +++ b/hts.c @@ -1764,7 +1764,7 @@ static hFILE *hts_hfile(htsFile *fp) { case bcf: // fall through case bam: return bgzf_hfile(fp->fp.bgzf); case cram: return cram_hfile(fp->fp.cram); - case text_format: return fp->fp.hfile; + case text_format: // fall through case vcf: // fall through case fastq_format: // fall through case fasta_format: // fall through