kaplibs: Fix line transposition bug.

Bad data could lead to an infinite loop.