Page 1 of 1

[Solved] Bug in SimpleAES Module

Posted: Thu Mar 12, 2020 1:18 pm
by Caronte3D
Hello, I want to share the solution to a bug in the simpleAES module, which has had me blocked for days :evil:
I can't find the thread for this module in the forum, that's why I open a new one.

The solution is simply to correct two ReAllocateMemory lines that did not use the destination variable, so when the result was a larger block of memory, everything gets corrupted and the program quits without any apparent error.

This are the two procedures where the ReAllocateMemory did not have the destination variable at the beginning:

Code: Select all

  Procedure.i SimpleAES_CryptMemory(*Key, Mode.i, *Memory, Size.i = -1, *Options.SimpleAES_Config = 0)
    Protected Cipher.i, NewSize, *NewMemory
    If Size = -1 : Size = MemorySize(*Memory) : EndIf       
    *NewMemory = AllocateMemory(Size + 32, #PB_Memory_NoClear)   
    Cipher = SimpleAES_StartCipher(*Key, Mode, *Options)
    NewSize = SimpleAES_AddCipherBuffer(Cipher, *Memory, Size, *NewMemory, #True)
    SimpleAES_FinishCipher(Cipher)   

    *NewMemory=ReAllocateMemory(*NewMemory, NewSize)

    ProcedureReturn *NewMemory
  EndProcedure
 
  
  Procedure.i SimpleAES_Base64Decoder(Base64String.s)
    Protected Base64Size.i, *Base64, *Memory, Size.i
    Base64Size = StringByteLength(Base64String, #PB_Ascii)
    *Base64 = AllocateMemory(Base64Size + 1, #PB_Memory_NoClear)
    PokeS(*Base64, Base64String, Base64Size, #PB_Ascii)
    Size = Base64Size + 64
    *Memory = AllocateMemory(Size, #PB_Memory_NoClear)
    Size = Base64DecoderBuffer(*Base64, Base64Size, *Memory, Size)
    FreeMemory(*Base64)

    *Memory=ReAllocateMemory(*Memory, Size)

    ProcedureReturn *Memory
  EndProcedure

Re: [Solved] Bug in SimpleAES Module

Posted: Thu Mar 12, 2020 1:35 pm
by Fred
Where did you find this module ?

Re: [Solved] Bug in SimpleAES Module

Posted: Thu Mar 12, 2020 1:43 pm
by Kwai chang caine

Re: [Solved] Bug in SimpleAES Module

Posted: Thu Mar 12, 2020 1:45 pm
by Caronte3D
Ah! It's true, I forget to search in the german forum!
Thanks! :wink:

Re: [Solved] Bug in SimpleAES Module

Posted: Thu Mar 12, 2020 1:50 pm
by Kwai chang caine
Glad to can help a little bit :wink:

Re: [Solved] Bug in SimpleAES Module

Posted: Thu Mar 12, 2020 1:54 pm
by Fred
Better post in the original thread then. And thx KCC :)

Re: [Solved] Bug in SimpleAES Module

Posted: Thu Mar 12, 2020 3:31 pm
by Caronte3D
I don't have access to the german forum (can't pass register page :lol: ) because I don't understand the language.
Maybe someone can post this link on the simpleAES module thread:wink:

Re: [Solved] Bug in SimpleAES Module

Posted: Thu Mar 12, 2020 3:44 pm
by #NULL
Caronte3D wrote:Maybe someone can post this link on the simpleAES module thread:wink:
Just did that.

Re: [Solved] Bug in SimpleAES Module

Posted: Thu Mar 12, 2020 6:58 pm
by Caronte3D
#NULL wrote:Just did that.
Thank you #NULL :wink: