tl;dr - if you're adding two numbers in your algorithm (like finding the midpoint in a binary search), make sure their sum can be represented in the resultant type.
The bug is subtle. It does not arise out of engineering failure, but rather is a byproduct of engineering success manifesting itself as a durable solution being used beyond any time frame anticipated in the specification. It's of a kind with Y2k or Y2038.