Skip to content

faidx --write-index invalid free with process substitution regions #2142

Description

@ASLeonard

It seems using a process substitution for extraction regions can cause issues with --write-index. I ran almost the same command on the same data using the two-pass approach in #2118 and never hit this issue, so may be related to the region list already being consumed before freeing at the end?

# error
samtools faidx --write-index -r <(echo -e "1\n2\n3") -o region.fa.gz genome.fa.gz
free(): invalid next size (fast)
Aborted

# no error
echo -e "1\n2\n3" > temp.txt
samtools faidx --write-index -r temp.txt -o region.fa.gz genome.fa.gz

GDB tracked the error back to this free, but all the variables were optimised out despite trying to recompile htslib/samtools more debug friendly.

fai_destroy(fai);

This was run with

samtools 1.21-13-g86fd06e-dirty
Using htslib 1.21-15-g1d2e493b-dirty

-Alex

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions