diff --git a/protected/gatk-protected/src/main/java/org/broadinstitute/sting/gatk/walkers/indels/IndelRealigner.java b/protected/gatk-protected/src/main/java/org/broadinstitute/sting/gatk/walkers/indels/IndelRealigner.java index a9b14e40b..bd1125354 100644 --- a/protected/gatk-protected/src/main/java/org/broadinstitute/sting/gatk/walkers/indels/IndelRealigner.java +++ b/protected/gatk-protected/src/main/java/org/broadinstitute/sting/gatk/walkers/indels/IndelRealigner.java @@ -1462,6 +1462,8 @@ public class IndelRealigner extends ReadWalker { case EQ: case X: case I: + if ( fromIndex + elementLength > actualReadBases.length ) + throw new UserException.MalformedBAM(read, "the CIGAR string is inconsistent with the number of bases in the read"); System.arraycopy(actualReadBases, fromIndex, readBases, toIndex, elementLength); System.arraycopy(actualBaseQuals, fromIndex, baseQuals, toIndex, elementLength); fromIndex += elementLength; diff --git a/protected/gatk-protected/src/test/java/org/broadinstitute/sting/gatk/walkers/indels/IndelRealignerIntegrationTest.java b/protected/gatk-protected/src/test/java/org/broadinstitute/sting/gatk/walkers/indels/IndelRealignerIntegrationTest.java index 275ababda..46c6efb0c 100644 --- a/protected/gatk-protected/src/test/java/org/broadinstitute/sting/gatk/walkers/indels/IndelRealignerIntegrationTest.java +++ b/protected/gatk-protected/src/test/java/org/broadinstitute/sting/gatk/walkers/indels/IndelRealignerIntegrationTest.java @@ -47,6 +47,7 @@ package org.broadinstitute.sting.gatk.walkers.indels; import org.broadinstitute.sting.WalkerTest; +import org.broadinstitute.sting.utils.exceptions.UserException; import org.testng.annotations.Test; import java.util.Arrays; @@ -100,7 +101,7 @@ public class IndelRealignerIntegrationTest extends WalkerTest { @Test public void testLods() { HashMap e = new HashMap(); - e.put( "-LOD 60", base_md5 ); + e.put("-LOD 60", base_md5); e.put( "-LOD 1 --consensusDeterminationModel USE_SW", "4bf28d3c0337682d439257874377a681" ); for ( Map.Entry entry : e.entrySet() ) { @@ -148,7 +149,7 @@ public class IndelRealignerIntegrationTest extends WalkerTest { @Test public void testMaxReadsInMemory() { HashMap e = new HashMap(); - e.put( "--maxReadsInMemory 10000", base_md5 ); + e.put("--maxReadsInMemory 10000", base_md5); e.put( "--maxReadsInMemory 40000", base_md5 ); for ( Map.Entry entry : e.entrySet() ) { @@ -169,4 +170,12 @@ public class IndelRealignerIntegrationTest extends WalkerTest { executeTest("test realigner nWayOut", spec1); } + @Test(expectedExceptions = RuntimeException.class) // because TESTNG wraps UserExceptions in RuntimeExceptions + public void testBadCigarString() { + WalkerTestSpec spec = new WalkerTestSpec( + "-T IndelRealigner -R " + b37KGReference + " -I " + privateTestDir + "Realigner.error.bam -L 19:5787200-5787300 -targetIntervals 19:5787205-5787300 -o %s", + 1, + Arrays.asList("FAILFAILFAILFAILFAILFAILFAILFAIL")); + executeTest("test bad cigar", spec); + } }