Bug 36847 - Android/Mono: "Cannot Parse Chunk Size" exception being thrown from System.Net.HttpWebResponse.CopyToAsync() call
Summary: Android/Mono: "Cannot Parse Chunk Size" exception being thrown from System.Ne...
Status: RESOLVED NORESPONSE
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 6.0.0
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Marek Habersack
URL:
Depends on:
Blocks:
 
Reported: 2015-12-10 18:59 UTC by Jeremy Cook
Modified: 2017-06-28 11:51 UTC (History)
3 users (show)

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


Attachments
Full chunked response as captured from wireshark (214.43 KB, application/octet-binary)
2015-12-10 18:59 UTC, Jeremy Cook
Details


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 on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED NORESPONSE

Description Jeremy Cook 2015-12-10 18:59:45 UTC
Created attachment 14230 [details]
Full chunked response as captured from wireshark

# Steps to reproduce
We have a device that reports back a JPEG image using chunked transfer-encoding.  After the final "0" length chunk there is some extra data that the device sends that is not part of the chunked response (and shouldn't be there), and is causing an exception to be thrown when the data is parsed into a MemoryStream.   

// Assume that response object below has the chunked data.   The following code throws the exception:
// response is of type System.Net.HttpWebResponse
using (var respStream = response.GetResponseStream())
{
   var retstrm = new MemoryStream();
   // the next line throws the exception.
   await respStream.CopyToAsync(retstrm);
}

The data looks something like this (i've removed a lot of the chunked data for brevity).
---------------------------------------------------------
HTTP/1.1 200 OK
X-Content-Type-Options: nosniff
Cache-Control: no-cache, no-store, must-revalidate
Content-Type: image/jpeg
Transfer-Encoding: chunked

8000
......JFIF.....,.,.....C..............
..
< remaining chunked data removed for brevity>
0

HTTP/1.1 202 ACCEPTED
Cache-Control: no-cache, no-store, must-revalidate
Server: gSOAP/2.7
Content-Type: text/xml; charset=utf-8
Content-Length: 0
Connection: keep-alive
-----------------------------------------------------------


# Expected behavior
This should copy the data into a MemoryStream object without exception.   This works fine on UWP platform.  Also, other HTTP clients (web browsers) are able to consume the stream with the extra data at the end without an issue.

# Actual behavior
This call throws an exception that is entitled "Cannot Parse Chunk Size". 

# Supplemental info (logs, images, videos)
Here's a stack trace of the exception that is thrown:
 (##) WebException: Cannot parse chunk size.
12-10 10:24:01.251 I/mono-stdout( 1460):        at System.Net.WebConnection.EndRead (System.Net.HttpWebRequest request, IAsyncResult result) [0x0016b] in /Users/builder/data/lanes/2098/3efa14c4/source/mono/mcs/class/System/System.Net/WebConnection.cs:984 
12-10 10:24:01.251 I/mono-stdout( 1460):   at System.Net.WebConnectionStream.EndRead (IAsyncResult r) [0x0003c] in /Users/builder/data/lanes/2098/3efa14c4/source/mono/mcs/class/System/System.Net/WebConnectionStream.cs:412 
       at System.Net.WebConnection.EndRead (System.Net.HttpWebRequest request, IAsyncResult result) [0x0016b] in /Users/builder/data/lanes/2098/3efa14c4/source/mono/mcs/class/System/System.Net/WebConnection.cs:984 
  at System.Net.WebConnectionStream.EndRead (IAsyncResult r) [0x0003c] in /Users/builder/data/lanes/2098/3efa14c4/source/mono/mcs/class/System/System.Net/WebConnectionStream.cs:412 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/2098/3efa14c4/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /Users/builder/data/lanes/2098/3efa14c4/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:201 
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/2098/3efa14c4/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:170 
  at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/2098/3efa14c4/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:142 
  at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1+ConfiguredTaskAwaiter[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/2098/3efa14c4/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:580 
  at System.IO.Stream+<CopyToAsyncInternal>c__async0.MoveNext () [0x000a6] in /Users/builder/data/lanes/2098/3efa14c4/source/mono/external/referencesource/mscorlib/system/io/stream.cs:171 
--- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/2098/3efa14c4/source/mono/external/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:143 
  at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /Users/builder/data/lanes/2098/3efa14c4/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:201 
12-10 10:24:01.251 I/mono-stdout( 1460): --- End of stack trace from previous location where exception was thrown ---


# Test environment (full version information)
Microsoft Visual Studio Professional 2015
Version 14.0.24720.00 Update 1
Microsoft .NET Framework
Version 4.6.01055

Installed Version: Professional

Visual Basic 2015   00322-40000-00000-AA135
Microsoft Visual Basic 2015

Visual C# 2015   00322-40000-00000-AA135
Microsoft Visual C# 2015

Visual C++ 2015   00322-40000-00000-AA135
Microsoft Visual C++ 2015

Windows Phone SDK 8.0 - ENU   00322-40000-00000-AA135
Windows Phone SDK 8.0 - ENU

Application Insights Tools for Visual Studio Package   1.0
Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2015.1 (Beta8)   14.1.11106.0
ASP.NET and Web Tools 2015.1 (Beta8)

ASP.NET Web Frameworks and Tools 2012.2   4.1.41102.0
For additional information, visit http://go.microsoft.com/fwlink/?LinkID=309563

ASP.NET Web Frameworks and Tools 2013   5.2.30624.0
For additional information, visit http://www.asp.net/

Common Azure Tools   1.5
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

KofePackagePackage Extension   1.0
KofePackagePackage Visual Studio Extension Detailed Info

Microsoft Azure Mobile Services Tools   1.4
Microsoft Azure Mobile Services Tools

Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers

NuGet Package Manager   3.3.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

PreEmptive Analytics Visualizer   1.2
Microsoft Visual Studio extension to visualize aggregated summaries from the PreEmptive Analytics product.

SQL Server Data Tools   14.0.50616.0
Microsoft SQL Server Data Tools

TypeScript   1.7.4.0
TypeScript for Microsoft Visual Studio

Visual C++ for Cross Platform Mobile Development   1.0
Visual C++ for Cross Platform Mobile Development

Visual C++ for Cross Platform Mobile Development   1.0
Visual C++ for Cross Platform Mobile Development

Visual Studio Tools for Universal Windows Apps   14.0.24720.00
The Visual Studio Tools for Universal Windows apps allow you to build a single universal app experience that can reach every device running Windows 10: phone, tablet, PC, and more. It includes the Microsoft Windows 10 Software Development Kit.

Xamarin   4.0.0.1689 (f860fe4)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android   6.0.0.34 (3efa14c)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.iOS   9.2.1.51 (3c0ec35)
Visual Studio extension to enable development for Xamarin.iOS.

OS Name	Microsoft Windows 10 Enterprise N
Version	10.0.10240 Build 10240
Other OS Description 	Not Available
OS Manufacturer	Microsoft Corporation
System Name	CHIMERA-DEV
System Manufacturer	Hewlett-Packard
System Model	HP Z800 Workstation
System Type	x64-based PC
System SKU	FF825AV
Processor	Intel(R) Xeon(R) CPU           X5560  @ 2.80GHz, 2794 Mhz, 4 Core(s), 8 Logical Processor(s)
Processor	Intel(R) Xeon(R) CPU           X5560  @ 2.80GHz, 2794 Mhz, 4 Core(s), 8 Logical Processor(s)
BIOS Version/Date	Hewlett-Packard 786G5 v03.57, 7/15/2013
SMBIOS Version	2.6
Embedded Controller Version	255.255
BIOS Mode	Legacy
BaseBoard Manufacturer	Hewlett-Packard
BaseBoard Model	Not Available
BaseBoard Name	Base Board
Platform Role	Workstation
Secure Boot State	Unsupported
PCR7 Configuration	Not Available
Windows Directory	C:\Windows
System Directory	C:\Windows\system32
Boot Device	\Device\HarddiskVolume1
Locale	United States
Hardware Abstraction Layer	Version = "10.0.10240.16392"
User Name	Not Available
Time Zone	Pacific Standard Time
Installed Physical Memory (RAM)	96.0 GB
Total Physical Memory	96.0 GB
Available Physical Memory	89.0 GB
Total Virtual Memory	110 GB
Available Virtual Memory	102 GB
Page File Space	14.0 GB
Page File	C:\pagefile.sys
Device Guard Virtualization based security	Not enabled
A hypervisor has been detected. Features required for Hyper-V will not be displayed.
Comment 1 Marek Habersack 2015-12-14 13:19:59 UTC
I will need a full sample project that reproduces the issue, preferably accessing the service you mention in your post. If you can't reveal the service URL publicly, please mail me at grendel@xamarin.com with the URL after attaching the sample project to this bug, thanks!
Comment 2 Adam Hartley [MSFT] 2017-06-28 11:51:01 UTC
Because we have not received a reply to our request for more information we are closing this issue. If you are still encountering this issue, please reopen the ticket with the requested information. Thanks!