Bug 17801 - Missing Content-Type in header cause host crashes
Summary: Missing Content-Type in header cause host crashes
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: WCF assemblies (show other bugs)
Version: 3.2.x
Hardware: All All
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-02-16 00:41 UTC by AlexZ
Modified: 2017-09-06 16:55 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 17801 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
NEW

Description AlexZ 2014-02-16 00:41:41 UTC
Reproduction:
Send any post without content-type to WCF host will cause its crashes.

Exception:
Unhandled Exception:
System.ArgumentNullException: Argument cannot be null.
Parameter name: contentType
  at System.ServiceModel.Channels.WebMessageEncoder.IsContentTypeSupported (System.String contentType) [0x00011] in C:\cygwin\sources\mono\mcs\class\System.ServiceModel.Web\System.ServiceModel.Channels\WebMessageEncoder.cs:70
  at System.ServiceModel.Channels.Http.HttpReplyChannel.CreatePostMessage (System.ServiceModel.Channels.Http.HttpContextInfo ctxi) [0x0001d] in C:\cygwin\sources\mono\mcs\class\System.ServiceModel\System.ServiceModel.Channels.Http\HttpReplyChannel.cs:198
  at System.ServiceModel.Channels.Http.HttpReplyChannel.TryReceiveRequest (TimeSpan timeout, System.ServiceModel.Channels.RequestContext& context) [0x000aa] in C:\cygwin\sources\mono\mcs\class\System.ServiceModel\System.ServiceModel.Channels.Http\HttpReplyChannel.cs:172
  at System.ServiceModel.Channels.ReplyChannelBase.<BeginTryReceiveRequest>m__1B (TimeSpan tout, System.ServiceModel.Channels.RequestContext& ctx) [0x00036] in C:\cygwin\sources\mono\mcs\class\System.ServiceModel\System.ServiceModel.Channels\ReplyChannelBase.cs:126 

Effect:
Version from 2.10.x to 3.2.6(the latest)
The reason is CreatePostMessage(without try-catch block) expecting a bool from IsContentTypeSupported, but IsContentTypeSupported throw a ArgumentNullException.

Fix:
File: mono\mcs\class\System.ServiceModel.Web\System.ServiceModel.Channels\WebMessageEncoder.cs Line#70
--------------------------------------------------------------------------------
public override bool IsContentTypeSupported (string contentType)
  {
   if (contentType == null)
      //Bad code, commend it: throw new ArgumentNullException ("contentType");
   return false;  //just return false
   return true;
  }
--------------------------------------------------------------------------------
It's a simple patch, please include this in next version.
Comment 1 AlexZ 2014-02-16 00:43:25 UTC
*comment
Comment 2 Miguel de Icaza [MSFT] 2015-12-24 15:07:38 UTC
Can you provide a test case for this, and show what .NET would do in this case?
Comment 3 AlexZ 2015-12-25 16:13:26 UTC
Hi, that repro is in my first post. 
.NET will catch that exception but Mono forget to handle it.