Fix FEN validation of pawns on first or eighth rank

The FEN validation check intended to reject pawns on the first or eighth rank uses the `Rank` enum values in a bitwise OR operation:

`if (pieces(PAWN) & (RANK_1 | RANK_8))`

`RANK_1 | RANK_8` evaluates to the integer `0 | 7 == 7` instead of a bitboard, so the expression only tests squares A1, B1 and C1. As a result, unsupported positions with pawns elsewhere on the first or eighth rank are silently accepted. For instance, `position fen 3P3k/8/8/8/8/8/8/3K4 w - - 0 1` is accepted even though the pawn on d8 makes the position unsupported.

Use the `Rank1BB | Rank8BB` bitboard constants so any pawn on the first or eighth rank are correctly rejected.

closes https://github.com/official-stockfish/Stockfish/pull/6887

No functional change
This commit is contained in:
zungur
2026-06-10 12:44:57 +02:00
committed by Joost VandeVondele
parent 7b37032885
commit 5595cb20ea
2 changed files with 2 additions and 1 deletions
+1
View File
@@ -198,6 +198,7 @@ Nour Berakdar (Nonlinear)
Ofek Shochat (OfekShochat, ghostway) Ofek Shochat (OfekShochat, ghostway)
Ondrej Mosnáček (WOnder93) Ondrej Mosnáček (WOnder93)
Ondřej Mišina (AndrovT) Ondřej Mišina (AndrovT)
Onur Zungur (zungur)
Oskar Werkelin Ahlin Oskar Werkelin Ahlin
Ömer Faruk Tutkun (OmerFarukTutkun) Ömer Faruk Tutkun (OmerFarukTutkun)
Pablo Vazquez Pablo Vazquez
+1 -1
View File
@@ -270,7 +270,7 @@ Position::set(const string& fenStr, bool isChess960, StateInfo* si) {
if (rank != RANK_1 || file != FILE_NB) if (rank != RANK_1 || file != FILE_NB)
return PositionSetError("Invalid FEN. Board state encoding ended but cursor not at end."); return PositionSetError("Invalid FEN. Board state encoding ended but cursor not at end.");
if (pieces(PAWN) & (RANK_1 | RANK_8)) if (pieces(PAWN) & (Rank1BB | Rank8BB))
return PositionSetError("Unsupported position. Pawns on the first or eighth rank."); return PositionSetError("Unsupported position. Pawns on the first or eighth rank.");
if (count<KING>(WHITE) != 1 || count<KING>(BLACK) != 1) if (count<KING>(WHITE) != 1 || count<KING>(BLACK) != 1)