Position Causes Stockfish and Komodo To Crash

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

syzygy
Posts: 5557
Joined: Tue Feb 28, 2012 11:56 pm

Re: Position Causes Stockfish and Komodo To Crash

Post by syzygy »

Sesse wrote: Sat Dec 19, 2020 12:20 am
syzygy wrote: Wed Dec 16, 2020 6:59 pm Where do the security boundaries lie? That is where you need to check.
Well, here's a related question: My chess site allows users to probe a running Stockfish' hash for fairly arbitrary positions. I would like to verify the FENs in the frontend, to make sure Stockfish does not crash on them. How should I go about this?
Frontend as in the browser? That wouldn't be particularly safe.
Fulvio
Posts: 395
Joined: Fri Aug 12, 2016 8:43 pm

Re: Position Causes Stockfish and Komodo To Crash

Post by Fulvio »

Sesse wrote: Sat Dec 19, 2020 2:37 pm It also appears to be rudimentary, e.g. doesn't test if both sides are in check:
https://github.com/ornicar/scalachess/b ... scala#L172
It also depends on the language you can/want use.
c++ isn't so good for internet development, but I can point you to the SCID's code:
https://github.com/benini/scid/blob/git ... .cpp#L2665
https://github.com/benini/scid/blob/git ... n.cpp#L270

which can be used like:

Code: Select all

#include <cstdio>
#include "position.h"

int main() {
	auto fen = "nbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR K KQkq - 0 1";
	if (Position().ReadFromFEN(fen) != OK) {
		std::printf("invalid");
	}
}
compiled with "g++ --std=c+17 thenamefileoftheabovecode.cpp position.cpp"
Fulvio
Posts: 395
Joined: Fri Aug 12, 2016 8:43 pm

Re: Position Causes Stockfish and Komodo To Crash

Post by Fulvio »

Michel wrote: Sat Dec 19, 2020 2:49 pm You have not answered my question. I repeat. Do you think it would be ok for ld to crash when encountering an unknown file format? A simple yes or no is sufficient.
Your question has been answered many times: Stockfish requires valid input, otherwise it's behavior is undefined.
I can post another link to this very simple concept, that when you design something you also state the prerequisites necessary for it to work:
https://blog.llvm.org/posts/2011-05-13- ... ould-know/
but you will not be able to understand it, because you do not want to.
crash is evil, nothing should ever crash...
yes, but sometimes it is acceptable if you trust...
no, no, you're trying to taint my soul!!
not at all, we can trust our fellow citizens and build walls just around the city...
you are the devil! I want the highest wall around my house, better my room, and I will never let anything in without checking it ten million times...
Michel
Posts: 2272
Joined: Mon Sep 29, 2008 1:50 am

Re: Position Causes Stockfish and Komodo To Crash

Post by Michel »

Fulvio wrote: Sat Dec 19, 2020 3:53 pm
Michel wrote: Sat Dec 19, 2020 2:49 pm You have not answered my question. I repeat. Do you think it would be ok for ld to crash when encountering an unknown file format? A simple yes or no is sufficient.
Your question has been answered many times: Stockfish requires valid input, otherwise it's behavior is undefined.
I can post another link to this very simple concept, that when you design something you also state the prerequisites necessary for it to work:
https://blog.llvm.org/posts/2011-05-13- ... ould-know/
but you will not be able to understand it, because you do not want to.
crash is evil, nothing should ever crash...
yes, but sometimes it is acceptable if you trust...
no, no, you're trying to taint my soul!!
not at all, we can trust our fellow citizens and build walls just around the city...
you are the devil! I want the highest wall around my house, better my room, and I will never let anything in without checking it ten million times...
You still haven't answered my question... Again: do you think it would be ok for ld to crash when encountering an unknown file format?
Ideas=science. Simplification=engineering.
Without ideas there is nothing to simplify.
Sesse
Posts: 300
Joined: Mon Apr 30, 2018 11:51 pm

Re: Position Causes Stockfish and Komodo To Crash

Post by Sesse »

syzygy wrote: Sat Dec 19, 2020 3:22 pm Frontend as in the browser? That wouldn't be particularly safe.
No, there's a separate frontend (middleware if you wish) that I control and that is talking to Stockfish in this case.
Sesse
Posts: 300
Joined: Mon Apr 30, 2018 11:51 pm

Re: Position Causes Stockfish and Komodo To Crash

Post by Sesse »

Fulvio wrote: Sat Dec 19, 2020 3:36 pm It also depends on the language you can/want use.
c++ isn't so good for internet development, but I can point you to the SCID's code:
https://github.com/benini/scid/blob/git ... .cpp#L2665
https://github.com/benini/scid/blob/git ... n.cpp#L270
That doesn't test semantics either, e.g. side not to move is not in check. Just like Lichess' code.
Fulvio
Posts: 395
Joined: Fri Aug 12, 2016 8:43 pm

Re: Position Causes Stockfish and Komodo To Crash

Post by Fulvio »

Sesse wrote: Sat Dec 19, 2020 4:47 pm
Fulvio wrote: Sat Dec 19, 2020 3:36 pm It also depends on the language you can/want use.
c++ isn't so good for internet development, but I can point you to the SCID's code:
https://github.com/benini/scid/blob/git ... .cpp#L2665
https://github.com/benini/scid/blob/git ... n.cpp#L270
That doesn't test semantics either, e.g. side not to move is not in check. Just like Lichess' code.
I think it does, if you look at the last FEN in the tests I already posted:
https://github.com/benini/scid/blob/git ... n.cpp#L295
Sesse
Posts: 300
Joined: Mon Apr 30, 2018 11:51 pm

Re: Position Causes Stockfish and Komodo To Crash

Post by Sesse »

OK, fine, but it doesn't have any double-check tests; e.g., it accepts rnbqkbnr/ppppppN1/3N1N2/8/8/8/PPPPPPP1/R1BQKB1R b - - 0 1 (a triple-check).
Fulvio
Posts: 395
Joined: Fri Aug 12, 2016 8:43 pm

Re: Position Causes Stockfish and Komodo To Crash

Post by Fulvio »

Sesse wrote: Sat Dec 19, 2020 5:52 pm it accepts rnbqkbnr/ppppppN1/3N1N2/8/8/8/PPPPPPP1/R1BQKB1R b - - 0 1
That's mate and it is also considered valid by Stockfish.
This is what it is considered invalid (plus max 16 pieces for each side):
https://github.com/benini/scid/blob/git ... .cpp#L1580

If you want to exclude positions that cannot be reached in a normal game that would be trickier.
Are you aware of any position of that type that cause problems with Stockfish?
Michel
Posts: 2272
Joined: Mon Sep 29, 2008 1:50 am

Re: Position Causes Stockfish and Komodo To Crash

Post by Michel »

Sesse wrote: Sat Dec 19, 2020 5:52 pm OK, fine, but it doesn't have any double-check tests; e.g., it accepts rnbqkbnr/ppppppN1/3N1N2/8/8/8/PPPPPPP1/R1BQKB1R b - - 0 1 (a triple-check).
I doubt that SF would have issues handling triple checks. Such a position is only illegal in the sense that it has no ancestor.

Of course this is also a mate position and it is debatable if the GUI is allowed to make a UCI engine search a mate position.
Ideas=science. Simplification=engineering.
Without ideas there is nothing to simplify.