Re-introduce bounds check removed in fcea6742c142fdbfdf53d17c862bfae7652fae3b
https://phabricator.kde.org/D16010
BUG: 398320