uchess icon indicating copy to clipboard operation
uchess copied to clipboard

Pawn promotion results in panic on negative count input to strings.Repeat()

Open jfkw opened this issue 2 years ago • 0 comments

On pawn promotion e.g. g8=Q, function pkg/util.getCapturedPieces() calculates an incorrect negative count of the promoted piece e.g. Q=-1. Using this negative count as subsequent input will cause standard library function strings.Repeat() to panic.

A sample FEN position that can reproduce the panic in the next move is:

"fen": "rnbqk2r/pppp2Pp/3bpn2/5p2/8/8/PPPPPPP1/RNBQKBNR w KQkq - 0 1"

The resulting traceback is not reproduced here since unescaped terminal codes are unreadable without newlines.

A PR to prevent the panic is forthcoming.

jfkw avatar Mar 26 '23 23:03 jfkw