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

Fix hts_hfile() for compressed text_format files #1826

Merged
merged 1 commit into from
Aug 23, 2024

Conversation

daviesrob
Copy link
Member

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 the output 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.

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.
@whitwham whitwham merged commit cf6e166 into samtools:develop Aug 23, 2024
9 checks passed
@daviesrob daviesrob deleted the hts_hfile_fix branch August 23, 2024 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants