jamescourtney / FlatSharp

Fast, idiomatic C# implementation of Flatbuffers
Apache License 2.0
497 stars 50 forks source link

Arithmetic operation resulted in an overflow #369

Closed gemoglobin closed 1 year ago

gemoglobin commented 1 year ago

runningSum can be greater than int

private static int GetMaxSizeOf_cd3f24f7f5404ee3b955702852d4c3ab(global::xxx value)
            {
                checked
                {

                    int count = value.Length;
                    int runningSum = 14;

                    for (int i = 0; i < value.Length; i = unchecked(i + 1))
                    {
                        var current = value[i];

                        SerializationHelpers.EnsureNonNull(current);
                        runningSum += GetMaxSizeOf_1b71d9af4ac24a1585ce26f9cc20b473(current);
                    }

                    return runningSum;
                }
            }
jamescourtney commented 1 year ago

It sounds like your data is too large. FlatBuffers can support at most 2GB due to signed 32 bit integers as a critical data structure. FlatSharp has a (somewhat artificial) limit of 1GB.

jamescourtney commented 1 year ago

That said -- GetMaxSize truly does compute the worst case. You might have luck if you were to just try to serialize the data into a ~1GB array. If FlatSharp goes over a limit, you'll get a BufferTooSmallException.

However, if you are that close to the limit, you should explore ways to partition your data.