Skip to content

fix: treat bcf_sr_add_reader 0 as error instead of success - #523

Closed
kvg wants to merge 1 commit into
rust-bio:masterfrom
kvg:fix/bcf-sr-add-reader-return
Closed

kvg wants to merge 1 commit into
rust-bio:masterfrom
kvg:fix/bcf-sr-add-reader-return

Conversation

@kvg

@kvg kvg commented Sep 10, 2026

Copy link
Copy Markdown

I hit this while streaming a VCF from a gs:// bucket in a Jupyter Lab notebook. A failed open didn't return an error. It segfaulted and killed the notebook kernel.

The cause is in IndexedReader::new. htslib's bcf_sr_add_reader returns 1 on success and 0 on failure. This code used >= 0, treated failure as success, and then dereferenced the NULL header. from_path never hits it because it checks existence in Rust first; from_url does.

SyncedReader::add_reader in this crate already checks res == 0. This PR does the same, and also null-checks hts_open in tbx::Reader before hts_get_format.

I've added two tests (IndexedReader::from_url and tbx::Reader::from_url) on a missing file:// path. Before the fix, they abort with a null pointer dereference error. After the fix, they now return Err as expected.

(Unrelated one-liner: header_hashmap.get("SQ") so the test crate compiles on current rustc.)

IndexedReader was using >= 0, but htslib's bcf_sr_add_reader returns 1 on success and 0 on failure. Thus, a failed from_url open dereferenced a NULL header and crashed. Similar issue in tbx::Reader calling hts_get_format on a NULL hts_open.
@kvg
kvg marked this pull request as draft September 10, 2026 07:50
@kvg kvg closed this Sep 10, 2026
@kvg
kvg deleted the fix/bcf-sr-add-reader-return branch September 10, 2026 07:50
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.

1 participant