Possible bug in GNAT Util.Encoders.AES

I was getting a range error in util-encoders.aes.adb. I’ve tracked it down to a bug in the code.

I don’t know if this has already been reported. In utilada_2.6.0, src/sys/encoders/util-encoders-ads.adb, around line 1545, where it says

 Remain := Input'Last - First; 

This causes the arithmetic in line 1551 to be incorrect, causing the range error. it should read

    Remain := Input'Last - First + 1;

Where it says

    Encrypt(0, Output(Last..Last + 16), Key);

This is obviously wrong because it would have 17 characters. it should read

    Encrypt(0, Output(Last .. Last + 15), Key);

Once you do that, the code just works.

1 Like

Indeed, I agree with your remark, it should be Last + 15 since AES blocks are 16 bytes. I was not aware of this issue.