Merge off-by-one crash fixes found and fixed in HEAD by Andrew Bartlett.