Skip to content

read.vcfR() coredump with empty lines in input #198

@ntakebay

Description

@ntakebay

Hi, I noticed that read.vcfR("test.vcf") caused core dump (and R quits) with the following error:

/usr/include/c++/11/bits/stl_vector.h:1045: std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = std::__cxx11::basic_string; _Alloc = std::allocator<std::__cxx11::basic_string >; std::vector<_Tp, _Alloc>::reference = std::__cxx11::basic_string&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]: Assertion '__n < this->size()' failed.
Aborted (core dumped)

This is caused by the statement:

body <- .read_body_gz(file, stats = stats, nrows = nrows, 
    skip = skip, cols = cols, convertNA = as.numeric(convertNA), 
    verbose = as.numeric(verbose))

Here is an example input vcf file which causes this problem (also I'm attaching this text file; please unzip it to get the vcf file before using it).

##fileformat=VCFv4.2
##fileDate=20220321
##source=PLINKv1.90
##contig=<ID=L103,length=476>
##contig=<ID=L105,length=689>
##INFO=<ID=PR,Number=0,Type=Flag,Description="Provisional reference allele, may not be based on real reference genome">
##FORMAT=<ID=GT,Number=1,Type=String,Description="Genotype">
#CHROM POS ID REF ALT QUAL FILTER INFO FORMAT Car_3A11_n_n Car_3B11_n_n Car_3C11_n_n

L103 475 L103_475 t c . . PR GT 0/0 0/0 0/0
L105 688 L105_688 c t . . PR GT 0/0 ./. 0/1

NOTE: there are two empty lines after "#CHROM..." line (I accidentally put these empty lines, and I discovered this issue). If there is 0 or 1 empty line there, read.vcfR() works as intended. I checked if there is any rules about empty lines in VCF specification, but I couldn't find it. But core dumping doesn't seem to be a good behavior here, so I thought that you might want to deal with this issue.

Version info:
R version 4.12 on linux x86_64
vcfR version 1.12.0

Thank you,
Naoki
test.vcf.zip
i

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions