unicode/norm: fix bug that causes panic.

To reproduce the bug, a segment must start with a starter that decomposes
in several starters of which the last one must combine backwards. This
Sequence must then be followed by enough modifiers to overflow the buffer.

The bug was caused by an incorrect computation of trailing non-starters.

This bug shows that there is a better way to do stream-safe:
1) always start a new segment if a starter follows a rune with CCC > 0.
2) combine consecutive starters early

Doing so would avoid the insertion of CGJ before starters.

Change-Id: I75c3a504ca8bc43e9b20ef5b8a588dd012506e97
Reviewed-on: https://go-review.googlesource.com/11283
Reviewed-by: Nigel Tao <nigeltao@golang.org>
3 files changed