Johannes Alef - 2022-09-20

I have a C# program that calls Snap7 via DLLImport to Upload entire blocks from a Type 300 PLC.
Some of the DBs are rather large. One of them for example has a loadsize of 91666 bytes.
The data is only 26164 bytes but with header and data for a user defined datatype that is used the block gets this large.
When I try to upload this block, my program just crashes and in the windows event log I find an error that usually indicates heap corruption (exceptioncode 0xc0000374). Exception Handling in C# does not seem able to prevent this. When I remove data from the data block to make it smaller (below 60000 bytes, I haven't tested for the exact value at which it breaks yet. 70000 breaks as well), the upload works.

This is the code that my program calls (from snap7.net.cs).

        [DllImport(S7Consts.Snap7LibName)]
        protected static extern int Cli_FullUpload(IntPtr Client, int BlockType, int BlockNum, byte[] UsrData, ref int Size);
        public int FullUpload(int BlockType, int BlockNum, byte[] UsrData, ref int Size)
        {
            return Cli_FullUpload(Client, BlockType, BlockNum, UsrData, ref Size);
        }

This is just a guess on my part, but is there anything in snap7 that limits the buffer to 65535 bytes?
I have attached a file that contains a db that allows to replicate this behaviour.