TAESEncryption.EncryptStream causing stack overflow on Apache module

Adding TAESEncryption on a desktop application was straightforward, but, when I used almost the same code on an Apache module I received a access violation error and the service was immediately terminated.
Investigating further I realized that this method was causing an stack overflow. Adding ThreadStackSize 4000000 to the Apache configuration solved the problem.
The stack overflow is clearly caused by the allocation of two variables (buffer and outputBuffer) totaling 320k bytes on the stack, while four other, far smaller variables (P, IVc, C and w) are allocated on the heap. It looks weird to me. Is there any reason for doing things this way?

Hello Sergio,

Do you mean

function AES_EncryptBinaryBuffer(inputBuffer: PAnsiChar;
inputSizeBytes: integer; outputBuffer: PAnsiChar; outputSizeBytes: PInteger;
key: PAnsiChar; keySizeBits: integer; IVIn: integer; IV: PAnsiChar;
padding: integer; mode: integer): integer; cdecl;

instead of AES_Encrypt?

I would need to investigate further, but this may be due to the fact that the underlying code is in C whereas the calling function is a Delphi wrapper.




I mean...

procedure TAESEncryption.EncryptStream(s: TStream; o: TStream);
Buffer: array [0 .. 160000] of AnsiChar;
outputBuffer: array [0 .. 160000] of AnsiChar;