dotnet / dotnet/wcf

UnixDomainSocketBinding ignoring set ReaderQuotas

Open
#5,660 5 comments 0 reactions 0 assignees View on GitHub
triaged
Dominant language
C#
Stars
1.8k
Forks
576
Avg merge
6d 9h
Merged PRs (30d)
2

Description

**Describe the bug**
When using the `UnixDomainSocketBinding` for the WCF Client the set `ReaderQuotas` are ignored which may lead to an exception:
"[...] The maximum array length quota (16384) has been exceeded while reading XML data. This quota may be increased by changing the MaxArrayLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader."

I have set the mentioned `MaxArrayLength` to a higher value which works well on `NetNamedPipeBinding` but not on `UnixDomainSocketBinding`.

**To Reproduce**
If needed i can try to create a small sample project the next days but i add informations after my investigations in **Additional context** below.

**Expected behavior**
The set `ReaderQuotas` of the `UnixDomainSocketBinding` to be considered like in other Bindings like `NetNamedPipeBinding`

**Additional context**
After some investigation of this behavior i found that the `NetNamedPipeBinding` add's the created `BinaryMessageEncodingBindingElement` of the `_encoding` field when `CreateBindingElements` is called.

```
public override BindingElementCollection CreateBindingElements()
{ // return collection of BindingElements
BindingElementCollection bindingElements = new BindingElementCollection();
// order of BindingElements is important
// add encoding
bindingElements.Add(_encoding);
// add transport security
WindowsStreamSecurityBindingElement transportSecurity = CreateTransportSecurity();
if (transportSecurity != null)
{
bindingElements.Add(transportSecurity);
}
// add transport (named pipes)
bindingElements.Add(_namedPipe);

return bindingElements.Clone();
}
```

While the `UnixDomainSocketBinding` does **not** add the `BinaryMessageEncodingBindingElement` of the `_encoding` field:

```
public override BindingElementCollection CreateBindingElements()
{
// return collection of BindingElements
BindingElementCollection bindingElements = new BindingElementCollection();
BindingElement transportSecurity = CreateTransportSecurity();
if (transportSecurity != null)
{
bindingElements.Add(transportSecurity);
}
_transport.ExtendedProtectionPolicy = _security.Transport.ExtendedProtectionPolicy;
bindingElements.Add(_transport);

return bindingElements.Clone();
}
```

As workaround i created my own binding which derives form `UnixDomainSocketBinding` and overrides the `CreateBindingElements`.
In my override i get the value of `_encoding` via reflection and add it at first position of the `BindingElementCollection` (like also done at `NetNamedPipeBinding`). With that binding the `ReaderQuotas` are considered and the Data get read correctly.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.