[Solved] Bug in SimpleAES Module

Just starting out? Need help? Post your questions and find answers here.
User avatar
Caronte3D
Addict
Addict
Posts: 1355
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

[Solved] Bug in SimpleAES Module

Post 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
Fred
Administrator
Administrator
Posts: 18161
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: [Solved] Bug in SimpleAES Module

Post by Fred »

Where did you find this module ?
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: [Solved] Bug in SimpleAES Module

Post by Kwai chang caine »

Last edited by Kwai chang caine on Thu Mar 12, 2020 1:51 pm, edited 1 time in total.
ImageThe happiness is a road...
Not a destination
User avatar
Caronte3D
Addict
Addict
Posts: 1355
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: [Solved] Bug in SimpleAES Module

Post by Caronte3D »

Ah! It's true, I forget to search in the german forum!
Thanks! :wink:
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: [Solved] Bug in SimpleAES Module

Post by Kwai chang caine »

Glad to can help a little bit :wink:
ImageThe happiness is a road...
Not a destination
Fred
Administrator
Administrator
Posts: 18161
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: [Solved] Bug in SimpleAES Module

Post by Fred »

Better post in the original thread then. And thx KCC :)
User avatar
Caronte3D
Addict
Addict
Posts: 1355
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: [Solved] Bug in SimpleAES Module

Post 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:
#NULL
Addict
Addict
Posts: 1497
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: [Solved] Bug in SimpleAES Module

Post by #NULL »

Caronte3D wrote:Maybe someone can post this link on the simpleAES module thread:wink:
Just did that.
User avatar
Caronte3D
Addict
Addict
Posts: 1355
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: [Solved] Bug in SimpleAES Module

Post by Caronte3D »

#NULL wrote:Just did that.
Thank you #NULL :wink:
Post Reply