Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / September 2007

Tip: Looking for answers? Try searching our database.

AccessViolationException from OSSOCK.recv when using WebRequest

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Max Bolingbroke - 26 Sep 2007 22:37 GMT
Hi,

I have some extremely simple code using WebRequest (isolated from a
larger application):

       static void Main()
       {
           WebRequest w = WebRequest.Create("http://
www.google.com"); // Works
           //WebRequest w = WebRequest.Create(@"http://
finance.yahoo.com"); // Does not work
           w.BeginGetResponse(
               delegate(IAsyncResult ar)
               {
                   try
                   {
                       //Console.WriteLine("Beginning to get the
response"); // Works if I insert this line
                       WebResponse r = w.EndGetResponse(ar);
                       Console.WriteLine(new
StreamReader(r.GetResponseStream()).ReadToEnd());
                   }
                   catch (Exception x)
                   { Console.WriteLine(x.ToString()); }
               }, null);

           Thread.Sleep(Timeout.Infinite);
       }

However, when I run the code as shown above (with or without Visual
Studio attached, in both Debug and Release mode) I get the following
exception message printed to the console:
System.IO.IOException: Unable to read data from the transport
connection: Attemp
ted to read or write protected memory. This is often an indication
that other me
mory is corrupt.. ---> System.AccessViolationException: Attempted to
read or wri
te protected memory. This is often an indication that other memory is
corrupt.
  at System.Net.UnsafeNclNativeMethods.OSSOCK.recv(IntPtr
socketHandle, Byte* p
innedBuffer, Int32 len, SocketFlags socketFlags)
  at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset,
Int32 size,
SocketFlags socketFlags, SocketError& errorCode)
  at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset,
Int32 size,
SocketFlags socketFlags)
  at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32
offset, Int32 s
ize)
  --- End of inner exception stack trace ---
  at System.Net.ConnectStream.Read(Byte[] buffer, Int32 offset, Int32
size)
  at System.IO.StreamReader.ReadBuffer()
  at System.IO.StreamReader.ReadToEnd()
  at
DownloadTester.Program.<>c__DisplayClass1.<Main>b__0(IAsyncResult ar)

As the comments suggest, this same code works fine for retrieving a
page from Google or if I write something to the console before using
the response stream in the anonymous delegate! This is an extremely
puzzling result.

Can anyone shed some light on this problem?

Thanks in advance,
Max
Max Bolingbroke - 27 Sep 2007 11:47 GMT
I have traced this problem to the imon.dll component of the NOD32
Antivirus suite (specifically, version 2.7 with internet filter
version 1.002 build 1013) and will be filing a bug report with them.
The full stack trace at the point of failure is:

    ntdll.dll!_KiFastSystemCallRet@0()
    ntdll.dll!_NtWaitForSingleObject@12()  + 0xc bytes
    kernel32.dll!_WaitForSingleObjectEx@12()  + 0x84 bytes
    ntdll.dll!ExecuteHandler2@20()  + 0x26 bytes
    ntdll.dll!ExecuteHandler@20()  + 0x24 bytes
>    ntdll.dll!_KiUserExceptionDispatcher@8()  + 0xf bytes
    imon.dll!20b2472a()
    [Frames below may be incorrect and/or missing, no symbols loaded for
imon.dll]
    imon.dll!20b20bca()
    imon.dll!20b06e21()
    imon.dll!20b23afa()
    imon.dll!20b23afa()
    imon.dll!20b239f1()
    imon.dll!20b239f1()
    imon.dll!20b239de()
    imon.dll!20b24d79()
    kernel32.dll!_MultiByteToWideChar@24()  + 0x76 bytes
    imon.dll!20b19418()
    imon.dll!20b212ae()
    imon.dll!20b0602a()
    [Managed to Native Transition]
    System.dll!System.Net.Sockets.Socket.Receive(byte[] buffer =
{Dimensions:[2]}, int offset = 0, int size,
System.Net.Sockets.SocketFlags socketFlags = None, out
System.Net.Sockets.SocketError errorCode = Success) + 0x139 bytes
    System.dll!System.Net.Sockets.Socket.Receive(byte[] buffer, int
offset, int size, System.Net.Sockets.SocketFlags socketFlags) + 0x1d
bytes
    System.dll!System.Net.Sockets.NetworkStream.Read(byte[] buffer, int
offset, int size) + 0x78 bytes
    System.dll!System.Net.PooledStream.Read(byte[] buffer, int offset,
int size) + 0x16 bytes
    System.dll!System.Net.ConnectStream.ReadSingleByte() + 0x45 bytes
    System.dll!System.Net.StreamChunkBytes.NextByte.get() + 0x1b bytes
    System.dll!
System.Net.ChunkParse.GetChunkSize(System.Net.IReadChunkBytes Source =
{System.Net.StreamChunkBytes}, out int chunkSize = 0) + 0x80 bytes
    System.dll!
System.Net.ConnectStream.ProcessReadChunkedSize(System.Net.StreamChunkBytes
ReadByteBuffer = {System.Net.StreamChunkBytes}) + 0x18 bytes
    System.dll!System.Net.ConnectStream.ReadChunkedSync(byte[] buffer =
{Dimensions:[1024]}, int offset = 0, int size = 1024) + 0x52 bytes
    System.dll!System.Net.ConnectStream.ReadWithoutValidation(byte[]
buffer, int offset, int size, bool abortOnError = true) + 0x58 bytes
    System.dll!System.Net.ConnectStream.Read(byte[] buffer = {Dimensions:
[1024]}, int offset = 0, int size) + 0x134 bytes
    DownloadTester.exe!
DownloadTester.Program.Main.AnonymousMethod(System.IAsyncResult ar =
{System.Net.ContextAwareResult}) Line 29 + 0x16 bytes    C#
    System.dll!System.Net.LazyAsyncResult.Complete(System.IntPtr
userToken) + 0x8c bytes
    System.dll!System.Net.ContextAwareResult.CompleteCallback(object
state) + 0x1a bytes
    mscorlib.dll!
System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext
executionContext, System.Threading.ContextCallback callback, object
state) + 0x81 bytes
    System.dll!System.Net.ContextAwareResult.Complete(System.IntPtr
userToken) + 0xa7 bytes
    System.dll!System.Net.LazyAsyncResult.ProtectedInvokeCallback(object
result, System.IntPtr userToken) + 0x77 bytes
    System.dll!System.Net.HttpWebRequest.ProcessResponse() + 0xe1 bytes
    System.dll!
System.Net.HttpWebRequest.SetResponse(System.Net.CoreResponseData
coreResponseData) + 0x19b bytes
    System.dll!System.Net.HttpWebRequest.SetAndOrProcessResponse(object
responseOrException) + 0x181 bytes
    System.dll!
System.Net.ConnectionReturnResult.SetResponses(System.Net.ConnectionReturnResult
returnResult = {System.Net.ConnectionReturnResult}) + 0x6c bytes
    System.dll!System.Net.Connection.ReadComplete(int bytesRead,
System.Net.WebExceptionStatus errorStatus) + 0x303 bytes
    System.dll!System.Net.Connection.ReadCallback(System.IAsyncResult
asyncResult) + 0xe1 bytes
    System.dll!
System.Net.Connection.ReadCallbackWrapper(System.IAsyncResult
asyncResult) + 0x44 bytes
    System.dll!System.Net.LazyAsyncResult.Complete(System.IntPtr
userToken) + 0x8c bytes
    System.dll!System.Net.ContextAwareResult.Complete(System.IntPtr
userToken) + 0x2f bytes
    System.dll!System.Net.LazyAsyncResult.ProtectedInvokeCallback(object
result, System.IntPtr userToken) + 0x77 bytes
    System.dll!
System.Net.Sockets.BaseOverlappedAsyncResult.CompletionPortCallback(uint
errorCode, uint numBytes, System.Threading.NativeOverlapped*
nativeOverlapped) + 0x10c bytes
    mscorlib.dll!
System.Threading._IOCompletionCallback.PerformIOCompletionCallback(uint
errorCode, uint numBytes, System.Threading.NativeOverlapped* pOVERLAP)
+ 0x7c bytes
    kernel32.dll!@BaseThreadInitThunk@12()  + 0x12 bytes
    ntdll.dll!__RtlUserThreadStart@8()  + 0x27 bytes

> Hi,
>
[quoted text clipped - 64 lines]
> Thanks in advance,
> Max
Max Bolingbroke - 27 Sep 2007 20:23 GMT
And ESET have told me that they aren't going to fix it because IMON is
known to be broken :-). I quote their reply below:

""
Hello,

In our next major release (3.0), we are doing away with IMON after
many years and replacing it with two more utilities.

In 1992, when NOD32 was introduced, very few programs operated at the
Winsock level. Today, in addition to Google and Microsoft, 100's of
other developers are creating software in this manner. That would be
fine, except for the fact that any app that operates here needs the
top spot in the stack, and only one program can have it.

As it is now, it can't be enabled at all on a server.

IMON was just the first layer of defense, a supplement. The strengths
of NOD32 are AMON, which scans every file that performs an action, as
it performs that action and the advanced heuristics which is stopping
90%+ of all new threats, before a definition is even written.

By quitting IMON now, you'll not only allow both programs to operate
together, but you'll also lose no coverage.

Thank you,
ESET Tech Support
""

> I have traced this problem to the imon.dll component of the NOD32
> Antivirus suite (specifically, version 2.7 with internet filter
[quoted text clipped - 164 lines]
> > Thanks in advance,
> > Max

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.