Fix ensureHeader with index

Change-Id: I368ee7061e2de7b76768e7bc72a6ecfce66e0880