official-pikafish / Pikafish

UCI xiangqi engine
http://pikafish.org
GNU General Public License v3.0
867 stars 162 forks source link

Pikfafish crash on invalid FEN #15

Closed jeffli678 closed 1 year ago

jeffli678 commented 1 year ago

Describe the issue

Pikafish engine crashes when an invalid FEN is sent through the fen command. It is not a big deal since the GUI front-end should not send such FEN positions in the first place. However, it would still be better not crash and send an error message according to the UCI protocal.

Expected behavior

No crash, and optionally return an error message about the situation.

Steps to reproduce

uci
fen foobar

Anything else?

(gdb) bt
#0  0x000055555555bf88 in Stockfish::Position::checkers_to(Stockfish::Color, Stockfish::Square, unsigned __int128) const ()
#1  0x000055555558e047 in Stockfish::Position::set(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, Stockfish::StateInfo*, Stockfish::Thread*) [clone .isra.0] ()
#2  0x000055555558e47e in Stockfish::(anonymous namespace)::position(Stockfish::Position&, std::__cxx11::basic_istringstream<char, std::char_traits<char>, std::allocator<char> >&, std::unique_ptr<std::deque<Stockfish::StateInfo, std::allocator<Stockfish::StateInfo> >, std::default_delete<std::deque<Stockfish::StateInfo, std::allocator<Stockfish::StateInfo> > > >&) ()
#3  0x0000555555596556 in Stockfish::UCI::loop(int, char**) ()
#4  0x000055555555af71 in main ()

Operating system

Linux

Pikafish version

56a1939cb100d5c2f7093299ced5c92fe80de3af

jeffli678 commented 1 year ago

The symbolized stack trace is:

__pthread_kill_implementation 0x00007ffff7ae8a7c
__pthread_kill_internal 0x00007ffff7ae8a7c
__GI___pthread_kill 0x00007ffff7ae8a7c
__GI_raise 0x00007ffff7a94476
__GI_abort 0x00007ffff7a7a7f3
__assert_fail_base 0x00007ffff7a7a71b
__GI___assert_fail 0x00007ffff7a8be96
Stockfish::Position::square<…> position.h:237
Stockfish::Position::set_state position.cpp:203
Stockfish::Position::set position.cpp:164
Stockfish::position uci.cpp:70
Stockfish::UCI::loop uci.cpp:271
main main.cpp:39
__libc_start_call_main 0x00007ffff7a7bd90
__libc_start_main_impl 0x00007ffff7a7be40
_start 0x000055555555b1c5

I checked the UCI protocol here http://wbec-ridderkerk.nl/html/UCIProtocol.html and it does not really specify a standard response on invalid FEN input. I guess we will just figure out one

jeffli678 commented 1 year ago

It appears to me that the intention is to crash if the input FEN is invalid, https://github.com/PikaCat-OuO/Pikafish/blob/580020e05b0aff782c8ab6bf58168bc113af7532/src/position.cpp#L166. If this is the case, this issue can be closed

PikaCat-OuO commented 1 year ago

Expected behavior. Stockfish does not check it too? You can crash stockfish in the same way.

jeffli678 commented 1 year ago

To be precise, stockfish (and pikafish as well) crashes intentionally. I will close this issue now.