ResourceHandler.Read throws System.NotSupportedException
-
What version of the product are you using? 79.1.350
-
What architecture x86 or x64? x86
-
On what operating system? Win10
-
Are you using
WinForms,WPForOffScreen? WinForms -
What steps will reproduce the problem?
- Put some site into the 'www' directory.
- Register FolderSchemaHandlerFactory for the directory.
- Run browser.
Example code to reproduce:
var directory = new DirectoryInfo($"{AppContext.BaseDirectory}www");
const string schemaName = "http";
const string domainName = "local.directory.com";
var url = $"{schemaName}://{domainName}/";
var browser = new ChromiumWebBrowser(url){
RequestContext = new RequestContext()
};
browser.RequestContext.RegisterSchemeHandlerFactory(
schemaName, domainName,
new FolderSchemeHandlerFactory(directory.FullName));
_mainForm.Controls.Add(browser);
_mainForm.Window.Show();
-
What is the expected output? What do you see instead? I expect it to run without any exceptions as in 75.1.143. I see
System.NotSupportedException: 'Unable to expand length of this stream beyond its capacity.'instead. -
Please provide any additional information below. I've found the last method that runs before I get exception in external code is
ResourceHandler.Read(Stream dataOut, out int bytesRead, IResourceReadCallback callback). I've reverted the last commit https://github.com/cefsharp/CefSharp/commit/453f8d2077df56e2724a2175719acdda9901c897 that changed this method and that fixed the issue.The workaround without building CefSharp is to wrap the ResourceHandler and use the
Readimplementation from 75.1.143. -
Does this problem also occur in the
CEFSample Application No.
Can you provide a stack trace please. I need more information on how to reproduce this, the description also needs to be updated as the problem is in ResourceHandler.
What file is causing the crash? Mime type? Extension? File size in bytes?
What are the values of the following tempBuffer.Length bytesRead dataOut.Length
Thanks
It's WOFF File, mime type: font/woff, extension: .woff, size: 71 787 bytes. I could not attach as it is proprietary licensed font.
What I get just before exception:
MimeType = "application/octet-stream"
Stream.Lenght = 71787
tempBuffer.Length = 65536
bytesRead = 6251
dataOut.Length = 1024
Then I get the exception and the call stack is:
mscorlib.dll!System.IO.UnmanagedMemoryStream.Write(byte[] buffer, int offset, int count)
CefSharp.dll!CefSharp.ResourceHandler.CefSharp.IResourceHandler.Read(System.IO.Stream dataOut, out int bytesRead, CefSharp.Callback.IResourceReadCallback callback) Line 183 C#
CefSharp.Core.dll!CefSharp::ResourceHandlerWrapper::Read(void* dataOut, int bytesToRead, int& bytesRead, scoped_refptr<CefResourceReadCallback>* callback) Line 49
Thanks for the added detail 👍
It's strange that dataOut.Length is only 1024 when the responseLength should have been set earlier. Possibly because the ResourceHandler.GetMimeType doesn't correctly map .woff. Additional mimeType mappings added in https://github.com/cefsharp/CefSharp/commit/d2a00e522e753182d0838532216bbdb1cad6307b
We should only read as many bytes as dataOut.Length, see commit https://github.com/cefsharp/CefSharp/commit/6a2175ad433f6ba953f3d2f681ddac17596a0d97
Thank you for the fix! 😀 🚀
Strange indeed. If mime type is application/octet-stream then every second dataOut.Length is just 1Kb. 🤷♂️ For example given 150Kb application/octet-stream it's 64kb, 1kb, 64kb, 1kb, 64kb. Then it's odd not strange. 😂 With correct mime type font/woff it's 64kb, 64kb, 64kb.
I wonder what's the purpose of this odd dataOut.Length. I guess that ResourceHandler.Read method eventually is called by chromium. CefSharp and CEF just allow to provide custom implementation.