From 5595cb20ea51aedf1c1ddcf852fa62d3b1d6e5c7 Mon Sep 17 00:00:00 2001 From: zungur Date: Wed, 10 Jun 2026 12:43:55 +0200 Subject: [PATCH] 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 --- AUTHORS | 1 + src/position.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index 59d692bb4..a7afa9f50 100644 --- a/AUTHORS +++ b/AUTHORS @@ -198,6 +198,7 @@ Nour Berakdar (Nonlinear) Ofek Shochat (OfekShochat, ghostway) Ondrej Mosnáček (WOnder93) Ondřej Mišina (AndrovT) +Onur Zungur (zungur) Oskar Werkelin Ahlin Ömer Faruk Tutkun (OmerFarukTutkun) Pablo Vazquez diff --git a/src/position.cpp b/src/position.cpp index e87091783..c9ff87a53 100644 --- a/src/position.cpp +++ b/src/position.cpp @@ -270,7 +270,7 @@ Position::set(const string& fenStr, bool isChess960, StateInfo* si) { if (rank != RANK_1 || file != FILE_NB) 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."); if (count(WHITE) != 1 || count(BLACK) != 1)