Resolve fdo#79913 by checking index bounds

Change-Id: I023a625d73724332245d612a61cb786acefc4cf2
Reviewed-on: https://gerrit.libreoffice.org/9791
Reviewed-by: Jean-Baptiste Faure <jbfaure@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>