[OcrFixEngine] - Fix accesing index outside of bounds.

This commit is contained in:
Ivandro Ismael 2016-09-12 03:04:43 +01:00
parent 5e0d1bd5da
commit 15afa97655
No known key found for this signature in database
GPG Key ID: A8832757DEFB7EDC

View File

@ -794,16 +794,17 @@ namespace Nikse.SubtitleEdit.Logic.Ocr
input = input.Insert(4, " "); input = input.Insert(4, " ");
} }
int nlLen = Environment.NewLine.Length;
int idx = input.IndexOf(Environment.NewLine + "-", StringComparison.Ordinal); int idx = input.IndexOf(Environment.NewLine + "-", StringComparison.Ordinal);
if (idx > 0 && idx + Environment.NewLine.Length + 1 < input.Length && char.IsUpper(input[idx + Environment.NewLine.Length + 1])) if (idx > 0 && idx + nlLen + 1 < input.Length && char.IsUpper(input[idx + nlLen + 1]))
{ {
input = input.Insert(idx + Environment.NewLine.Length + 1, " "); input = input.Insert(idx + Environment.NewLine.Length + 1, " ");
} }
idx = input.IndexOf(Environment.NewLine + "<i>-", StringComparison.Ordinal); idx = input.IndexOf(Environment.NewLine + "<i>-", StringComparison.Ordinal);
if (idx > 0 && char.IsUpper(input[idx + Environment.NewLine.Length + 4])) if (idx > 0 && idx + nlLen + 4 < input.Length && char.IsUpper(input[idx + nlLen + 4]))
{ {
input = input.Insert(idx + Environment.NewLine.Length + 4, " "); input = input.Insert(idx + nlLen + 4, " ");
} }
if (string.IsNullOrEmpty(lastLine) || if (string.IsNullOrEmpty(lastLine) ||