Bug 446077

Fix by add a check for if the row count is greater than the position and take the smaller one in avoid of array out of index.