fix wrapBuffer with negative length