merge from upstream, but lengths incorrectly handled