[Aggregator] Check if the index is valid.

Fixes an occasional segfault.