samtools/samtools — pull request #39 by peterjc (2013-03-29 16:19:57+00:00)
Title: Catch overflow in n_cigar and give an explicit error.

Due to the use of an unsigned 16bit integer, BAM files can only hold reads with up to 36635 CIGAR operators. SAM does not have this limit, but the samtools implementation (reasonably) also has the same 16bit limit.

Prior to this fix a very long CIGAR read would give a confusing 'unmatched CIGAR operation' warning and then abort with a core dump.

This issue was found tracing through an error reported on the MIRA mailing list, where a (valid) SAM file with an unusually long CIGAR string could not be converted to BAM using samtools:
http://www.freelists.org/post/mira_talk/Parse-error-at-line-84-unmatched-CIGAR-operation