在垃圾回收过程中的缓冲区溢出

在垃圾回收过程中的缓冲区溢出

本文介绍了心理调试的要求:在垃圾回收过程中的缓冲区溢出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前测试C#建一个C ++库(管理,我相信,我没有写)的顶部(.NET 4.5)WPF应用程序。对于不同的(实际)的原因,它是一台服务器上运行(安装了VS2012,是的,呸)。

该方案挂接到摄像机(经由库)并显示该图像帧它所接收。

有什么奇怪的是,我得到缓冲的超支的(缓冲区溢出我可以理解)。和垃圾收集过程中!

缓冲区溢出发生在APP.EXE已损坏了程序的内部状态。

信息其他各种可能有用的花絮:

  • 加大了吞吐量,使之成为现实越早(秒而不是分钟)
  • 运行在VS(调试或释放)停止它在所有发生的事情(或者至少是延迟时间比我ppared等待$ P $)
  • 有没有不安全在我的C#,唯一的'深奥'的事情我做的是将位图(从库中)到的BitmapSource (如)。
  • 在该库被编译为86,该exe了。

调用堆栈,同时每次:

  vcr110_clr0400.dll!__ crt_debugger_hook()未知
clr.dll!___ raise_securityfailure()未知
clr.dll!___ report_gsfailure()未知
clr.dll!CrawlFrame :: SetCurGSCookie(无符号长*)未知
clr.dll!StackFrameIterator ::初始化(Thread类*,类帧*,结构_REGDISPLAY *,无符号整型)未知
clr.dll!主题:: StackWalkFramesEx(结构_REGDISPLAY *,枚举StackWalkAction(*)(类CrawlFrame *,无效*),无效*,无符号整型,类帧*)未知
clr.dll!主题:: StackWalkFrames(枚举StackWalkAction(*)(类CrawlFrame *,无效*),无效*,无符号整型,类帧*)未知
clr.dll!CNameSpace :: GcScanRoots(无效(*)(Object类*,结构ScanContext *,无符号长),INT,INT,结构ScanContext *,类GCHeap *)未知
clr.dll!WKS :: gc_heap :: mark_phase(INT,INT)未知
clr.dll!WKS :: gc_heap :: GC1(无效)未知
clr.dll!WKS :: gc_heap :: garbage_collect(INT)未知
clr.dll!WKS :: GCHeap :: GarbageCollectGeneration(无符号整型,枚举WKS :: gc_reason)未知
clr.dll!WKS :: GCHeap :: GarbageCollectTry(INT,INT,INT)未知
clr.dll!WKS :: GCHeap :: GarbageCollect(INT,INT,INT)未知
clr.dll!GCInterface ::收集(INT,INT)未知
mscorlib.ni.dll!6dcd33e5()未知
[相框下面可能是不正确的和/或缺失,没有加载mscorlib.ni.dll符号]
mscorlib.ni.dll!6dcd33e5()未知
064afa73()未知
clr.dll!方法表:: FastBox(无效*)未知
clr.dll!方法表:: CallFinalizer(Object类*)未知
clr.dll!SVR :: CallFinalizer(Object类*)未知
clr.dll!SVR :: CallFinalizer(Object类*)未知
clr.dll!SVR :: CallFinalizer(Object类*)未知
clr.dll!WKS :: GCHeap :: FinalizerThreadWorker(无效*)未知
clr.dll!主题:: DoExtraWorkForFinalizer(无效)未知
clr.dll!主题:: DoExtraWorkForFinalizer(无效)未知
clr.dll!主题:: DoExtraWorkForFinalizer(无效)未知
clr.dll!WKS :: GCHeap :: FinalizerThreadStart(无效*)未知
clr.dll!主题:: intermediateThreadProc(无效*)未知
KERNEL32.DLL!@ BaseThreadInitThunk @ 12()未知
ntdll.dll!___RtlUserThreadStart@8()未知
ntdll.dll!__RtlUserThreadStart@8()未知
 

解决方案

看起来像一个内存破坏我;该库有可能使用不安全的和/或托管内存或固定内存...也许它不是寄托正确的内存位,或者太早拔除呢?

至于

这是因为调试器创建的进程使用不同的堆(即使你是在释放模式运行);用另一种堆是当随机内存损坏处理(我还没有发现这一点然而,许多源heisenbugs的来历,我认为这是在雷蒙陈博客的地方,但我只找到的)

编辑:引用找到了!从 MSDN

我最好的猜测是,则:C ++库败坏一些内存。在GC来了,发现损坏堆,崩溃。OR:C ++库也不忘针它使用作为图像的缓冲内存。在GC来了,移动存储器。 C ++库不知道,写入到现在无效的指针,导致腐败。在GC又来了,开始工作,现在已损坏的内存,崩溃

Currently testing a C# (.Net 4.5) WPF application built on top of a C++ library (managed, I believe, I didn't write it). For various (practical) reasons, it's running on a server (with VS2012 installed, yes, yuck).

The program hooks up to a camera (via the library) and displays the image frames that it receives.

What's weird is that I'm getting buffer overruns (buffer overflows I could understand). And during Garbage Collection!

A buffer overrun has occurred in App.exe which has corrupted the program's internal state.

Various other potentially useful tidbits of information:

  • Upping the 'throughput' makes it happen sooner (seconds instead of minutes)
  • Running in VS (debug or release) stops it happening at all (or at least delays it longer than I'm prepared to wait)
  • There's no unsafe in my C#, and the only 'esoteric' thing I'm doing is converting a bitmap (from the library) into a BitmapSource(like this).
  • The libraries are compiled for x86, the exe too.

Call stack, same every time:

vcr110_clr0400.dll!__crt_debugger_hook ()   Unknown
clr.dll!___raise_securityfailure () Unknown
clr.dll!___report_gsfailure ()  Unknown
clr.dll!CrawlFrame::SetCurGSCookie(unsigned long *) Unknown
clr.dll!StackFrameIterator::Init(class Thread *,class Frame *,struct _REGDISPLAY *,unsigned int)    Unknown
clr.dll!Thread::StackWalkFramesEx(struct _REGDISPLAY *,enum StackWalkAction (*)(class CrawlFrame *,void *),void *,unsigned int,class Frame *)   Unknown
clr.dll!Thread::StackWalkFrames(enum StackWalkAction (*)(class CrawlFrame *,void *),void *,unsigned int,class Frame *)  Unknown
clr.dll!CNameSpace::GcScanRoots(void (*)(class Object * *,struct ScanContext *,unsigned long),int,int,struct ScanContext *,class GCHeap *)  Unknown
clr.dll!WKS::gc_heap::mark_phase(int,int)   Unknown
clr.dll!WKS::gc_heap::gc1(void) Unknown
clr.dll!WKS::gc_heap::garbage_collect(int)  Unknown
clr.dll!WKS::GCHeap::GarbageCollectGeneration(unsigned int,enum WKS::gc_reason) Unknown
clr.dll!WKS::GCHeap::GarbageCollectTry(int,int,int) Unknown
clr.dll!WKS::GCHeap::GarbageCollect(int,int,int)    Unknown
clr.dll!GCInterface::Collect(int,int)   Unknown
mscorlib.ni.dll!6dcd33e5()  Unknown
[Frames below may be incorrect and/or missing, no symbols loaded for mscorlib.ni.dll]
mscorlib.ni.dll!6dcd33e5()  Unknown
064afa73()  Unknown
clr.dll!MethodTable::FastBox(void * *)  Unknown
clr.dll!MethodTable::CallFinalizer(class Object *)  Unknown
clr.dll!SVR::CallFinalizer(class Object *)  Unknown
clr.dll!SVR::CallFinalizer(class Object *)  Unknown
clr.dll!SVR::CallFinalizer(class Object *)  Unknown
clr.dll!WKS::GCHeap::FinalizerThreadWorker(void *)  Unknown
clr.dll!Thread::DoExtraWorkForFinalizer(void)   Unknown
clr.dll!Thread::DoExtraWorkForFinalizer(void)   Unknown
clr.dll!Thread::DoExtraWorkForFinalizer(void)   Unknown
clr.dll!WKS::GCHeap::FinalizerThreadStart(void *)   Unknown
clr.dll!Thread::intermediateThreadProc(void *)  Unknown
kernel32.dll!@BaseThreadInitThunk@12 () Unknown
ntdll.dll!___RtlUserThreadStart@8 ()    Unknown
ntdll.dll!__RtlUserThreadStart@8 () Unknown
解决方案

Looks like a memory corruption to me; the library is likely using unsafe and/or unmanaged memory or pinned memory... or maybe it is not pinning the correct bits of memory, or unpinning them too early?

As for:

This is because processes created by a debugger use a different heap (even if you are running in release mode); using this alternate heap is a known source of heisenbugs when dealing with random memory corruption (I have not found many sources on this point however; I thought it was on Raymond Chen blog somewhere but I only found this)

EDIT: reference found! From MSDN:

My best guess is then: the C++ library corrupts some memory. The GC comes, finds the heap corrupted, crash.OR: the C++ library does forget to pin the memory it is using as a buffer for images. The GC comes, move the memory. The C++ library does not know, writes to a now invalid pointer, causing corruption. The GC comes again, start to work on the now corrupted memory, crash

这篇关于心理调试的要求:在垃圾回收过程中的缓冲区溢出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 20:05