From 2e496f5d0b0a2a065e5f8162619c98b42bca1905 Mon Sep 17 00:00:00 2001
From: Yusuke Nojima <nojima@google.com>
Date: Fri, 16 Sep 2011 11:28:54 +0900
Subject: [PATCH] Fix editDistance() not to access the outside of
 mEditDistanceTable

editDistance() can access the outside of mEditDistanceTable when called
with strings that contain MAX_WORD_LENGTH_INTERNAL characters.

Change-Id: I996e6cf21bd6acd6584beb4046c10491a044191e
---
 native/src/correction.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/native/src/correction.h b/native/src/correction.h
index f3194b788e..41130ad77a 100644
--- a/native/src/correction.h
+++ b/native/src/correction.h
@@ -119,8 +119,9 @@ private:
     int mTerminalInputIndex;
     int mTerminalOutputIndex;
     unsigned short mWord[MAX_WORD_LENGTH_INTERNAL];
+    // Edit distance calculation requires a buffer with (N+1)^2 length for the input length N.
     // Caveat: Do not create multiple tables per thread as this table eats up RAM a lot.
-    int mEditDistanceTable[MAX_WORD_LENGTH_INTERNAL * MAX_WORD_LENGTH_INTERNAL];
+    int mEditDistanceTable[(MAX_WORD_LENGTH_INTERNAL + 1) * (MAX_WORD_LENGTH_INTERNAL + 1)];
 
     CorrectionState mCorrectionStates[MAX_WORD_LENGTH_INTERNAL];
 
-- 
GitLab