[prev in list] [next in list] [prev in thread] [next in thread] 

List:       vtk-developers
Subject:    Re: [vtk-developers] Possible fix for vtkImageStencilData::InsertAndMergeExtent
From:       David Gobbi <david.gobbi () gmail ! com>
Date:       2015-09-22 18:02:20
Message-ID: CANwS1=Eg-BUDvB-1dRrLVfN7i8VYtiFruJZ6TVUPXvhY-vyJRA () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hi Xabi,

Thanks, these will be very useful.

Cheers,
 - David

On Tue, Sep 22, 2015 at 9:43 AM, Xabi Riobe <xabivtk@gmail.com> wrote:

> Hi David,
>
> here is a sample that reproduce the crash, plus another one found recently.
> both are related to the use of vtkImageStencilData::Subtract
>
> you can compile ImageStencil.cxx with CMakeLists.txt (providing VTK_DIR in
> Cmake gui) and the proposed fixes are in vtkImageStencilFixed-VTK6.h that
> you can activate by uncommenting the defines FIX1 & FIX2 at the beginning
> of the sample.
>
> some comments are included in the .h close to the code fix (look for
> #ifdef FIX).
>
> The first crash (FIX1 in vtkImageStencilData::InsertAndMergeExtent) only
> occurs with Mac because it is related to the access of a wrong memory
> location pointing to a value that is always negative on Windows, passing
> the " while(condition) " , whereas on Mac the value can be positive. This
> happens when the insertion must be at the beginning of the list.
> For that reason, it is not always reproductible even on Mac, but you
> should get it with less than 10 executions.
>
> The second one (FIX2 in vtkImageStencilData::RemoveExtent) is always
> reproductible in both Mac/Windows and is related to the bad ordering of
> some elements in a list that causes an infinite loop later in the execution.
>
> Both crashes appear randomly later in the code, not at the location of the
> fixes.
>
> Let me know if you want me to test other cases or need more information.
>
>
> 2015-07-30 19:18 GMT+02:00 David Gobbi <david.gobbi@gmail.com>:
>
>> Hi Xabi,
>>
>> It doesn't look like the right fix, I suspect that the flaw in the logic
>> is somewhere else in that method.  Do you have any test code that I can use
>> to reproduce the bug?
>>
>>  - David
>>
>>
>> On Thu, Jul 30, 2015 at 1:05 AM, Xabi Riobe <xabivtk@gmail.com> wrote:
>>
>>> Hi,
>>>
>>> I'm in the process of migrating from 5.10.1 to 6.3 and have found a fix
>>> i had in vtkImageStencilData::InsertAndMergeExtent from one year ago.
>>>
>>> at the end of the method there is this loop:
>>>
>>>    while (r1 < clist[insertIndex-1])
>>>    {
>>>       clist[insertIndex] = clist[insertIndex-2];
>>>       clist[insertIndex+1] = clist[insertIndex-1];
>>>       insertIndex -= 2;
>>>    }
>>>
>>> and i have this line added : if (insertIndex <= 1) break;
>>> with the comment: "avoid accessing out of range elements, which produces
>>> incorrect stencil that causes a random crash later when used in
>>> vtkImageStencilExecute"
>>>
>>> This random crash occured on Mac, never reproduced on Windows.
>>>
>>> I was wondering if by looking at the code you think it's a correct fix
>>> that can be merged.
>>>
>>> Thanks
>>>
>>> Xabi.
>>>
>>
>>
>

[Attachment #5 (text/html)]

<div dir="ltr">Hi Xabi,<div><br></div><div>Thanks, these will be very \
useful.</div><div><br></div><div>Cheers,</div><div>  - David</div></div><div \
class="gmail_extra"><br><div class="gmail_quote">On Tue, Sep 22, 2015 at 9:43 AM, \
Xabi Riobe <span dir="ltr">&lt;<a href="mailto:xabivtk@gmail.com" \
target="_blank">xabivtk@gmail.com</a>&gt;</span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><div dir="ltr">Hi David,<div><br></div><div>here is a sample \
that reproduce the crash, plus another one found recently.</div><div>both are related \
to the use of  vtkImageStencilData::Subtract</div><div><br></div><div>you can compile \
ImageStencil.cxx with  CMakeLists.txt (providing VTK_DIR in Cmake gui) and the \
proposed fixes are in  vtkImageStencilFixed-VTK6.h that you can activate by \
uncommenting the defines FIX1 &amp; FIX2 at the beginning of the \
sample.</div><div><br></div><div>some comments are included in the .h close to the \
code fix (look for #ifdef FIX).</div><div><br></div><div>The first crash (FIX1 in \
vtkImageStencilData::InsertAndMergeExtent) only occurs with Mac because it is related \
to the access of a wrong memory location pointing to a value that is always negative \
on Windows, passing the &quot; while(condition) &quot; , whereas on Mac the value can \
be positive. This happens when the insertion must be at the beginning of the \
list.</div><div>For that reason, it is not always reproductible even on Mac, but you \
should get it with less than 10 executions.</div><div><br></div><div>The second one \
(FIX2 in vtkImageStencilData::RemoveExtent) is always reproductible in both \
Mac/Windows and is related to the bad ordering of some elements in a list that causes \
an infinite loop later in the execution.</div><div><br></div><div>Both crashes appear \
randomly later in the code, not at the location of the \
fixes.</div><div><br></div><div>Let me know if you want me to test other cases or \
need more information.</div><div><br></div></div><div class="gmail_extra"><br><div \
class="gmail_quote"><span class="">2015-07-30 19:18 GMT+02:00 David Gobbi <span \
dir="ltr">&lt;<a href="mailto:david.gobbi@gmail.com" \
target="_blank">david.gobbi@gmail.com</a>&gt;</span>:<br></span><div><div \
class="h5"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px \
#ccc solid;padding-left:1ex"><div dir="ltr">Hi Xabi,<div><br></div><div>It \
doesn&#39;t look like the right fix, I suspect that the flaw in the logic is \
somewhere else in that method.   Do you have any test code that I can use to \
reproduce the bug?</div><span><font \
color="#888888"><div><br></div></font></span><div><span><font color="#888888">  - \
David</font></span><div><div><br><div class="gmail_extra"><br><div \
class="gmail_quote">On Thu, Jul 30, 2015 at 1:05 AM, Xabi Riobe <span \
dir="ltr">&lt;<a href="mailto:xabivtk@gmail.com" \
target="_blank">xabivtk@gmail.com</a>&gt;</span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>I&#39;m in the process \
of migrating from 5.10.1 to 6.3 and have found a fix i had in  \
vtkImageStencilData::InsertAndMergeExtent from one year \
ago.</div><div><br></div><div>at the end of the method there is this \
loop:</div><div><br></div><div><div>     while (r1 &lt; \
clist[insertIndex-1])</div><div>     {</div><div>         clist[insertIndex] = \
clist[insertIndex-2];</div><div>         clist[insertIndex+1] = \
clist[insertIndex-1];</div><div>         insertIndex -= 2;</div><div>     \
}<br></div></div><div><br></div><div>and i have this line added :  if (insertIndex \
&lt;= 1) break;</div><div>with the comment:  &quot;avoid accessing out of range \
elements, which produces incorrect stencil that causes a random crash later when used \
in vtkImageStencilExecute&quot;</div><div><br></div><div>This random crash occured on \
Mac, never reproduced on Windows.</div><div><br></div><div>I was wondering if by \
looking at the code you think it&#39;s a correct fix that can be \
merged.</div><div><br></div><div>Thanks</div><span><font \
color="#888888"><div><br></div><div>Xabi.</div></font></span></div> \
</blockquote></div><br></div></div></div></div></div> \
</blockquote></div></div></div><br></div> </blockquote></div><br></div>



_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Search the list archives at: http://markmail.org/search/?q=vtk-developers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtk-developers



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic