Fix stack overflows and crashes when reading very long ladders