samtools / htslib

C library for high-throughput sequencing data formats
Other
799 stars 445 forks source link

Prevent crash when only FASTA entry has no sequence. #1507

Closed jkbonfield closed 1 year ago

jkbonfield commented 1 year ago

Eg the minimal file of:

>foo

Credit to OSS-Fuzz Fixes oss-fuzz 51378

jkbonfield commented 1 year ago

Note I did also wonder about changing the (ret = ...) < -1 condition to < 0 so a blank sequence is an error, but technically we do support empty sequences in FASTA.

Adittedly this is specifically the case of the last sequence being empty (which then triggers a bug if it also happens to be the first so hts_getline hasn't yet allocated a buffer), but if we accept empty sequences in FASTA elsewhere then I guess we should accept them at the end too. Not sure if that's good or bad, but this fix is consistent in that behaviour at least.