fairy-stockfish / Fairy-Stockfish

chess variant engine supporting Xiangqi, Shogi, Janggi, Makruk, S-Chess, Crazyhouse, Bughouse, and many more
https://fairy-stockfish.github.io/
GNU General Public License v3.0
618 stars 195 forks source link

Segfault with missing king and wrong castling information #215

Closed TomFryers closed 3 years ago

TomFryers commented 3 years ago

If one side has their king removed, but the FEN says they can still castle, a segmentation fault occurs.

Fairy-Stockfish 111220 LB by Fabian Fichter
xboard
setboard rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQ1BNR w KQkq - 0 1
analyze
info string classical evaluation enabled
1 -13 0 35 1 17500 0     e2e3
2 -32 0 68 2 34000 0     e2e3 d7d6
3 -74 0 133 3 66500 0    e2e3 e7e6 g1e2
4 -77 0 321 4 80250 0    d2d4 e7e6 e2e3 b8c6
5 -62 0 580 5 116000 0   e2e4 e7e6 d2d4 b8c6
6 -32 0 1236 6 154500 0  d2d4 c7c6 e2e4 d7d5 e4d5
7 -28 1 1758 7 159818 0  d2d4 c7c6 e2e4 d7d5 e4e5 e7e6 b1c3
8 -62 3 6151 8 198419 0  e2e4 e7e5 g1f3 b8c6 d2d4 e5d4 f3d4 g8f6
9 -28 5 11442 12 211888 0        e2e4 e7e5 g1f3 b8c6 d2d4 e5d4 f3d4
10 -16 8 19076 13 214337 0       e2e4 e7e5 g1f3 g8f6 f3e5 b8c6 e5c6 d7c6
11 1 13 30889 12 223833 0        d2d4 g8f6 b1c3 d7d5 a1b1 c7c6 e2e3 c8f5 g1f3
12 -31 37 82667 16 223424 0      d2d4 g8f6 e2e3 c7c6 c2c4 d7d5 d1b3 d5c4 f1c4 e7e6 b1c3 f8d6
13 -32 61 136574 16 223525 0     d2d4 g8f6 f2f3 d7d6 e2e4 b8d7 d4d5 c7c6 c2c4 h7h6 b1c3 e7e5 d5e6 f7e6 b2b3
14 -115 139 314878 20 226043 0   d2d4 g8f6 f2f3 b8c6 c2c3 d7d5 b2b4 e7e6 g2g4 f8d6 h2h4 c6e7 h4h5 e8g8
15 12 198 449964 21 226682 0     b1c3 g8f6 e2e4 e7e5 f1e2 c7c6 d2d3 f8c5 c3a4 c5f2 b2b3 c1a1
16 -1 235 539265 17 229376 0     b1c3 e7e6 c3b5 b8a6 e2e3 g8f6 b5c3 f6g4 c3e4 g4f2 e4f2 c1f1 b2b3 c1a1
Segmentation fault (core dumped)

Presumably depth 16 (or 17?) is when it considers castling.

These are obviously invalid FENs, but a more graceful mechanism is probably still a good idea.

gbtami commented 3 years ago

Seems this "issue" is popular again :) http://talkchess.com/forum3/viewtopic.php?f=7&t=76026

ianfab commented 3 years ago

This topic has been discussed many times for official Stockfish and the maintainers' conclusion always was that crashing on invalid input is expected, because in UCI it is the GUIs responsibility to validate input, not the engine's. I think in CECP it is not that clear cut, but I still do not see it as a major issue, since GUIs are not expected to send invalid input. Since however this is not specific to a certain position but rather in general whether FENs should be validated when using the XBoard protocol, I am closing this in favor of https://github.com/ianfab/Fairy-Stockfish/issues/87.