dotnet / dotnet/dotnet-api-docs
MaxBufferSize in WCF binding. Max value should be int.MaxValue-56
- Dominant language
- C#
- Stars
- 949
- Forks
- 1.7k
- Avg merge
- 3d 27m
- Merged PRs (30d)
- 49
Description
I know it is not recommended, but some application set the MaxBufferSize (and other properties) to
2.147.483.647 (int.MaxValue).
The problem is that when you configure it, you won't see any problem, since the WCF will not allocate 2GB array buffer (it is just the **max** size).
After some time, when you data grows, and your responses exceeds 2GB, WCF will try to allocate a byte array with 2.147.483.647 and it will throw a OOM Exception, in the method System.Runtime.Fx.AllocateByteArray: https://referencesource.microsoft.com/#System.ServiceModel.Internals/System/Runtime/Fx.cs,e64210856f0d3690.
You can easily simulate the problem with a Console App, writing:
var x = new byte[int.MaxValue];//Doesn't work
var y = new byte[int.MaxValue-56];//Works
If you change the max size to 2.147.483.591 (int.MaxValue-56), it will work.
Since the framework doesn't validate the maximum allowed value, we need to add this to the remarks section.
More info about array limits: https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/runtime/gcallowverylargeobjects-element#remarks
> The maximum index in any single dimension is 2,147,483,591 (0x7FFFFFC7) for byte arrays and arrays of single-byte structures, and 2,146,435,071 (0X7FEFFFFF) for other types.
Contributor guide
Assessment
This issue has not been assessed yet.