From 1e329df08da9be11021f4f43f0961befd2899ca6 Mon Sep 17 00:00:00 2001
From: Guillaume Pasero <guillaume.pasero@c-s.fr>
Date: Tue, 15 Dec 2015 19:04:43 +0100
Subject: [PATCH] BUG: Mantis-1107: fix out-of-buffer index

---
 .../Stereo/include/otbBijectionCoherencyFilter.txx | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/Modules/Registration/Stereo/include/otbBijectionCoherencyFilter.txx b/Modules/Registration/Stereo/include/otbBijectionCoherencyFilter.txx
index 1723af892e..c4f6307af3 100644
--- a/Modules/Registration/Stereo/include/otbBijectionCoherencyFilter.txx
+++ b/Modules/Registration/Stereo/include/otbBijectionCoherencyFilter.txx
@@ -265,12 +265,18 @@ BijectionCoherencyFilter<TDisparityImage,TOutputImage>
       ul[1] = (buffered.GetIndex()[1]+buffered.GetSize()[1]-1);
 
     ur = ul;
-    ur[0] += 1;
     ll = ul;
-    ll[1] += 1;
     lr = ul;
-    lr[0] += 1;
-    lr[1] += 1;
+    if (ul[0] < static_cast<IndexValueType>(buffered.GetIndex()[0] + buffered.GetSize()[0]-1))
+      {
+      ur[0] += 1;
+      lr[0] += 1;
+      }
+    if (ul[1] < static_cast<IndexValueType>(buffered.GetIndex()[1] + buffered.GetSize()[1]-1))
+      {
+      ll[1] += 1;
+      lr[1] += 1;
+      }
 
     double rx = tmpIndex[0] - static_cast<double>(ul[0]);
     double ry = tmpIndex[1] - static_cast<double>(ul[1]);
-- 
GitLab