See the attached testcase. The problem is described in a fixme in VisiblePosition::canonicalPosition
Created attachment 8954 [details] testcase
See also Bug 13736.