Hi,

thanks!

I also have one other patch in the pipeline fixing some input/output
buffer handling, likely even exploitable (although I discovered it by
spurious output in lichess-bot). The bug is kinda clear but also hard
to notice by accident - I only got it to happen a few times per day,
where it showed up as random \x00 bytes in UCI commands sent to
lichess-bot.

I will send the patch once sufficiently tested in the next week -
right now I already have it on my lichess-bot (which BTW is called
GNUPassant - it loves en passant captures, favors lines with them even
if they are otherwise kinda worse, and if no en passant happened, it
punishes the opponent by not checkmating the usual shortest-mate way,
but by instead capturing as many opponent pieces and promoting as many
pawns to queens as it can before mating).

You can see what I am doing on
https://github.com/divVerent/gnuchess/compare/master...divVerent:gnuchess:but_en_passant,
but obviously some of the changes shouldn't get into GNU Chess (at
least not unless behind an option), and the others aren't finished yet
- I'll send patches when I consider them well tested.

Thank you,

Rudolf "divVerent" Polzer

On Sun, Jun 1, 2025 at 8:14 AM Antonio Ceballos <acebal...@gmail.com> wrote:
>
> Hi Rudolf,
>
> Thanks for spotting this bug, and for the detailed description of the steps 
> you followed.
> I have reproduced it in the pre-release 6.3.0-pre2. It seems that it was 
> introduced in
> version 6.2.9.
>
> Your patch looks good and it fixes the problem indeed! Thanks for it! I will 
> include it
> in the upcoming version 6.3.0.
>
> Cheers,
> Antonio Ceballos
>
>
>
> On Fri, May 30, 2025 at 3:36 AM Rudolf Polzer <divver...@gmail.com> wrote:
>>
>> Hi,
>>
>> I am currently playing around with the GNU Chess engine and patching
>> around in it for fun, and while doing so, found some minor bugs in the
>> source.
>>
>> As I am new to the project and not yet clear about e.g. the coding
>> style, let me start with a simple and trivial fix: currently one
>> cannot correctly load EPD files; the following happens:
>>
>> ```
>> $ cat t
>> rnbqkb1r/pppppppp/5n2/8/4P3/8/PPPP1PPP/RNBQKBNR w KQkq - bm 1; id 1;
>> $ src/gnuchess  --easy
>> GNU Chess
>> Can't open file "(null)": Bad address - using defaults
>> White (1) : post
>> White (1) : depth 5
>> Search to a depth of 5.
>> White (1) : load t
>>
>>  : Best move = 1
>>
>> white  KQkq
>>
>> r n b q k b . r
>> p p p p p p p p
>> . . . . . n . .
>> . . . . . . . .
>> . . . . P . . .
>> . . . . . . . .
>> P P P P . P P P
>> R N B Q K B N R
>>
>> Error loading EPD file 't'.
>> White (1) : f4
>> 1. f4
>>
>> black  KQkq  f3
>>
>> r n b q k b . r
>> p p p p p p p p
>> . . . . . n . .
>> . . . . . . . .
>> . . . . P P . .
>> . . . . . . . .
>> P P P P . . P P
>> R N B Q K B N R
>>
>> Thinking...
>> 1 -6 0 2 a5
>> White (1) : 1 -1 0 4 b5
>> 1 +41 0 8 d5
>> 1 +43 0 21 Nc6
>> 2 +9 0 47 Nc6 Nc3
>> 3 +43 0 155 Nc6 Nc3 Nf6
>> 4 +9 0 788 Nc6 Nf3 Nf6 Nc3
>> 5 +37 0 2920 Nc6 Nf3 Nf6 Nc3 d5
>> 5 +37 1 5024 Nc6 Nf3 Nf6 Nc3 d5
>>
>> white  KQkq
>>
>> r . b q k b . r
>> p p p p p p p p
>> . . n . . n . .
>> . . . . . . . .
>> . . . . P P . .
>> . . . . . . . .
>> P P P P . . P P
>> R N B Q K B N R
>>
>>
>> My move is : Nc6
>> ```
>>
>> So it's not taking the free pawn on e4.
>>
>> If I instead don't load, but play the move from scratch, it reliably will.
>>
>> A clue is the "Error loading EPD file 't'." message, and indeed, the
>> code has a bug there - it uses strlen on a buffer that's initialized
>> empty (thus is always 0) when clearly sizeof was intended, and on
>> failure it seems the board is loaded into some variables but not into
>> others. After this patch:
>>
>> ```
>> From 7655b2c6bb98d1bfec5852124d05adec34df353d Mon Sep 17 00:00:00 2001
>> From: Rudolf Polzer <divver...@gmail.com>
>> Date: Thu, 29 May 2025 06:46:39 -0400
>> Subject: [PATCH 1/1] Fix loading EPD files.
>>
>> ---
>>  src/frontend/cmd.cc | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/src/frontend/cmd.cc b/src/frontend/cmd.cc
>> index f038e62..dacbd66 100644
>> --- a/src/frontend/cmd.cc
>> +++ b/src/frontend/cmd.cc
>> @@ -394,7 +394,7 @@ void cmd_load(void)
>>      printf (_("Board is wrong!\n"));
>>    } else {
>>      /* Read EPD file and send contents to engine */
>> -    if (build_setboard_cmd_from_epd_file(data, epd_filename, strlen(data))) 
>> {
>> +    if (build_setboard_cmd_from_epd_file(data, epd_filename, sizeof(data))) 
>> {
>>        SetDataToEngine( data );
>>        SetAutoGo( true );
>>      } else {
>> --
>> 2.39.5
>> ```
>>
>> it's taking the pawn just fine:
>>
>> ```
>> $ src/gnuchess --easy
>> GNU Chess
>> Can't open file "(null)": Bad address - using defaults
>> White (1) : post
>> White (1) : depth 5
>> Search to a depth of 5.
>> White (1) : load t
>>
>>  : Best move = 1
>>
>> white  KQkq
>>
>> r n b q k b . r
>> p p p p p p p p
>> . . . . . n . .
>> . . . . . . . .
>> . . . . P . . .
>> . . . . . . . .
>> P P P P . P P P
>> R N B Q K B N R
>>
>> White (1) : f4
>> 1. f4
>>
>> black  KQkq  f3
>>
>> r n b q k b . r
>> p p p p p p p p
>> . . . . . n . .
>> . . . . . . . .
>> . . . . P P . .
>> . . . . . . . .
>> P P P P . . P P
>> R N B Q K B N R
>>
>> Thinking...
>> Thinking...
>> 1 +168 0 2 Nxe4
>> Black (1) : 2 +130 0 130 Nxe4 Nc3
>> 3 +132 0 547 Nxe4 Nc3 d5 Nxe4 dxe4
>> 4 +117 0 1471 Nxe4 d3 Nc5 Nc3
>> 5 +135 1 5352 Nxe4 Nf3 d5 Nc3 Nc6 Nxe4 dxe4
>> 5 +135 1 7197 Nxe4 Nf3 d5 Nc3 Nc6 Nxe4 dxe4
>>
>> white  KQkq
>>
>> r n b q k b . r
>> p p p p p p p p
>> . . . . . . . .
>> . . . . . . . .
>> . . . . n P . .
>> . . . . . . . .
>> P P P P . . P P
>> R N B Q K B N R
>>
>>
>> My move is : Nxe4
>> ```
>>
>> Does this patch look correct? Hope Gmail didn't ruin things - I can
>> try using another address if it doesn't work well with this mailing
>> list, but would like any commits to be associated with this primary
>> one if possible.
>>
>> Thank you,
>>
>> Rudolf "divVerent" Polzer
>>

Reply via email to