Skip to content

Remove an assert in cram_index_build. - #2061

Merged
daviesrob merged 1 commit into
samtools:developfrom
jkbonfield:fix_2060
Aug 6, 2026
Merged

daviesrob merged 1 commit into
samtools:developfrom
jkbonfield:fix_2060

Conversation

@jkbonfield

Copy link
Copy Markdown
Contributor

If we don't have a compression header where expected it now fails in a more graceful manner.

Co-Authored-By: Shujie Xiang

Fixes #2060

Comment thread cram/cram_index.c Outdated
goto err;
assert(c->comp_hdr_block->content_type == COMPRESSION_HEADER);
if (c->comp_hdr_block->content_type != COMPRESSION_HEADER) {
hts_log_error("Expected a compression header block");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we've done an htell() just before reading the block, could we print its location in the error message, in a similar way to this example?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do, but it'll likely be seen by no-one. The assert has been there since 2013 and the first person to trigger it did it via fuzzing, so we can be pretty sure this is vanishingly rare in the wild, so more informative error messages are probably moot!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done as requested. I hope the fuzzers feel warm and fuzzy :-)

If we don't have a compression header where expected it now fails in a
more graceful manner.

Co-Authored-By: Shujie Xiang

Fixes samtools#2060

Signed-off-by: James Bonfield <jkb@sanger.ac.uk>
@daviesrob
daviesrob merged commit 4809e29 into samtools:develop Aug 6, 2026
17 checks passed
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.

Assertion failure in cram_index_build() on a malformed CRAM file

2 participants