python-chess icon indicating copy to clipboard operation
python-chess copied to clipboard

`was_into_check` behavior on multiple kings

Open winapiadmin opened this issue 1 month ago • 0 comments

was_into_check (L1995-L1997)

    def was_into_check(self) -> bool:
        king = self.king(not self.turn)
        return king is not None and self.is_attacked_by(self.turn, king)

Here it only picks one king.... but if the position loaded has multiple kings, it only return the bool of one king which depends on FEN parsing order, that means - a flipped position can bring different king of the corresponding side to move.

While it isn't too much - this is kind of UB for pseudo-legal FENs, and it affects Board.is_valid, Board.status and possibly its variants.

winapiadmin avatar Nov 03 '25 11:11 winapiadmin