Skip to content

CG tag and SEQ/CIGAR consistency. - #2089

Merged
daviesrob merged 2 commits into
samtools:developfrom
jkbonfield:cram-ins-overread
Sep 15, 2026
Merged

daviesrob merged 2 commits into
samtools:developfrom
jkbonfield:cram-ins-overread

Conversation

@jkbonfield

Copy link
Copy Markdown
Contributor

BAM moves the CG: cigar tag to the CIGAR field prior to validating sequence length and the cigar fields are logically consistent.

SAM does the consistency check before parsing CG, so it could fail. CRAM likewise. (Although technically both formats do not need to parse the tag, they do so for consistency with BAM.)

BAM has this check at the end, but SAM checks after reading SEQ and
before checking if we'll overwrite CIGAR with a CG tag.

CRAM uses bam_set1, which checks for SEQ/CIGAR consistency, but this
is also prior to aux tag parsing and CG->CIGAR migration.  The nature
of the bam_set1 API though is such that aux tags haven't yet been
parsed, so it is up to the caller to perform this test itself later or
to parse aux and replace cigar before calling bam_set1.

CRAM does however call bam_tag2cigar as even though it doesn't need
it, it's there for consistency of what takes priority.  sam_parse1
calls that function too, and potentially third party code, so checking
has been added there as well.

Credit to OSS_Fuzz
Fixes oss-fuzz issue 560967311

Signed-off-by: James Bonfield <jkb@sanger.ac.uk>
Normally this is detected and filtered out earlier, but see the
previous commit.  So we take the belt and braces approach and fix it
here too.

Signed-off-by: James Bonfield <jkb@sanger.ac.uk>
@daviesrob
daviesrob merged commit fe2a822 into samtools:develop Sep 15, 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.

2 participants