[Solved] Bug in SimpleAES Module
Posted: Thu Mar 12, 2020 1:18 pm
Hello, I want to share the solution to a bug in the simpleAES module, which has had me blocked for days
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:

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