View Issue Details

IDProjectCategoryView StatusLast Update
0031601CommunityOCCT:Modeling Algorithmspublic2024-03-01 15:06
Reporterabdullah Assigned Toakaftasev  
PrioritynormalSeveritycrash 
Status resolvedResolutionopen 
PlatformLinuxOSDebian 6.0 
Product Version7.3.0 
Target VersionUnscheduled 
Summary0031601: Modeling Algorithms - BRepOffset_Tool Segmentation Fault
Description
A patch as possible solution is provided.

This has been tested and reproduced against development branch 7.4.1, commit ae58f70718a089f84178d45a1bf9bee586d52d80

This bug is based on the FreeCAD bug:
https://tracker.freecadweb.org/view.php?id=2325

The segmentation fault happens in function BRepOffset_Tool::TryProject.

In the following code (starting in line 1815):

   TopoDS_Edge CurE = TopoDS::Edge(it.Value());
    Handle(Geom_Curve) C = BRep_Tool::Curve(CurE,L,f,l);
    if (C.IsNull()) {
      BRepLib::BuildCurve3d(CurE,BRep_Tool::Tolerance(CurE));
      C = BRep_Tool::Curve(CurE,L,f,l);
    }
    C = new Geom_TrimmedCurve(C,f,l);

The curve produced by the call to BRep_Tool::Curve(CurE,L,f,l) is null.

Consequently the curve inserted into the constructor of Geom_TrimmedCurve is null. This causes the segfault.

I do not know whether BuildCurve3d is faulty (it should necessarily provide a non-null curve or not). I only know that in this specific case, it produces a null curve.

A possible solution to avoid the segmentation fault (see patch below), is to test whether the curve produced by BuildCurve3d is null.

An alternative to returning Standard_False (as in the patch) is to raise an exception. As no other function of this class raises an exception. None of the other functions of this class returns an exception, this my unqualified reason for returning Standard_False instead. You know the code better than me and may prefer an exception instead.
 


















Steps To Reproduce
box b 50 50 10
explode b E
compound b_1 b_2 b_3 b_4 b_5 b_6 b_7 b_8 b_9 b_10 b_11 b_12 c
fillet s b 4 c
explode s F
offsetparameter 1.e-7 c a
offsetload s 1 s_11
offsetperform r
# OSD_Exception_ACCESS_VIOLATION: ACCESS VIOLATION at address 0x0000000000000000 during 'READ' operation


This bug is based on the FreeCAD bug:
https://tracker.freecadweb.org/view.php?id=2325

It is not easy to provide a way to reproduce it without FreeCAD. I am running a setup using a locally build FreeCAD with a locally build development branch of OCCT:
https://forum.freecadweb.org/viewtopic.php?f=10&t=47017&start=10#p405952

I think that based on the analysis above, you will be interested in preventing the segfault.

Of course, if you want to provide other code and would like me to test a possible patch or else, just contact me. I am ready to help.


Additional information
and documentation updates
This is a patch that prevents the segmentation fault.

diff --git a/src/BRepOffset/BRepOffset_Tool.cxx b/src/BRepOffset/BRepOffset_Tool.cxx
index af3ac106e1..b7c0d2310c 100644
--- a/src/BRepOffset/BRepOffset_Tool.cxx
+++ b/src/BRepOffset/BRepOffset_Tool.cxx
@@ -1820,0 +1821,3 @@ Standard_Boolean BRepOffset_Tool::TryProject
+ if (C.IsNull())
+ return Standard_False;
+
TagsNo tags attached.
Test case number

Activities

msv

2022-02-14 11:19

developer   ~0106886

Dear abdullah, It would help a lot in reproduction and fixing this bug if you provided a piece of isolated code that causes this bug. It will be OK if it will be a complete program with main() function doing all stuff.

dpasukhi

2024-01-30 12:27

administrator   ~0115006

Needs to analyze on latest version.
If be able to reproduce - needs to fix.

git

2024-02-08 20:03

administrator   ~0115057

Branch CR31601 has been created by Aleksei_S.

SHA-1: fe7ca7662a987ce2b197ef17058500ca17d88181


Detailed log of new commits:

Author: aleksei.stromkov
Date: Thu Feb 8 17:02:45 2024 +0000

    0031601: Modeling Algorithms - BRepOffset_Tool Segmentation Fault
    
    Added protection against null pointer dereferencing.
    Modified BRepOffset_MakeOffset::MakeThickSolid method.

git

2024-02-13 00:50

administrator   ~0115073

Branch CR31601 has been updated by astromko.

SHA-1: 7ef7d252f81dd529987aaef2f9cb532e70592651


Detailed log of new commits:

Author: astromko
Date: Mon Feb 12 21:50:46 2024 +0000

    0031601: Modeling Algorithms - BRepOffset_Tool Segmentation Fault
    
    Fixed the problem with negative volume values

git

2024-02-14 22:08

administrator   ~0115089

Branch CR31601 has been updated forcibly by astromko.

SHA-1: 171ea61394a04c97904ad0b79db566c746853606

git

2024-02-15 00:48

administrator   ~0115091

Branch CR31601 has been updated by astromko.

SHA-1: 3fca09976525451808fd5b4651dc0d4f78ec218b


Detailed log of new commits:

Author: astromko
Date: Wed Feb 14 21:48:42 2024 +0000

    0031601: Modeling Algorithms - BRepOffset_Tool Segmentation Fault
    
    Fixed 2 unit tests: "offset compshape A1" and "offset shape A1".

astromko

2024-02-15 13:29

developer   ~0115094

Jenkins: http://jenkins-test-10.nnov.opencascade.com/view/CR31601-master-astromko/

Regarding the changes.
In case of "if (NbOF <= NbF)" the "offsetperform" command is never executed in my tests with the message "ERROR. offsetperform operation not done.". Changed to "if (NbOF < NbF)".
And in case of "if (NbOF == NbF)" set myOffset to 0 to avoid reversing to negative volume value.

akaftasev

2024-02-19 14:10

developer   ~0115136

Last edited: 2024-02-19 14:13

The patch seems good, but test cases "offset faces_type_i" still remain, but now, these cases are OK (but it is not, because the resulted shapes the same as original: you can compare vprops of result and initial shape).
My suggestion is to add checking return value of method BRepOffset_Tool::TryProject().

Small remark - please, use 2 spaces instead of 4 in BRepOffset_Tool.cxx:
1884+ if (C.IsNull())
1885+ return Standard_False;

Please, add test case for this bug.

git

2024-02-22 16:52

administrator   ~0115152

Branch CR31601 has been updated forcibly by astromko.

SHA-1: 2844f1c1beeac17bffe01d3e557060cb529c8dc9

astromko

2024-02-23 18:06

developer   ~0115162

Added checking return value of method BRepOffset_Tool::TryProject().
Added a test case.
There are 18 failed tests that came from master after rebase. 17 from them have the error "ERROR: Process killed by elapsed limit". And 1 test is about exception.

akaftasev

2024-02-29 14:25

developer   ~0115198

Please, delete new bool variables "retVal" from BRepOffset_Tool.cxx and BRepOffset_Inter3d.cxx, and add whole method BRepOffset_Tool::TryProject() into "if" instead.

BRepOffset_MakeOffset.cxx:
1184+ if (NbOF == NbF)
1185+ myOffset = 0;
add brackets.

And run tests on Jecnkins again.

git

2024-02-29 15:56

administrator   ~0115200

Branch CR31601 has been updated forcibly by astromko.

SHA-1: 7a61d41be674f18b6d3f728cd7e5bb53b36f56b0

astromko

2024-02-29 17:00

developer   ~0115202

All remarks are fixed.

git

2024-03-01 15:06

administrator   ~0115209

Branch CR31601 has been updated forcibly by astromko.

SHA-1: 4ff3213b70bba746fa8e7353461348d9e9ca35bc

Issue History

Date Modified Username Field Change
2020-06-07 17:50 abdullah New Issue
2020-06-07 17:50 abdullah Assigned To => msv
2022-02-14 11:19 msv Note Added: 0106886
2022-06-24 15:48 azv Assigned To msv => vmigunov
2022-06-24 15:48 azv Target Version => 7.7.0
2022-06-24 15:48 azv Steps to Reproduce Updated
2022-06-24 15:48 azv Status new => assigned
2022-07-05 08:57 vmigunov Status assigned => resolved
2022-07-05 08:58 vmigunov Assigned To vmigunov => azv
2022-07-05 09:02 vmigunov Assigned To azv => vmigunov
2022-07-05 09:02 vmigunov Status resolved => assigned
2022-10-24 10:40 szy Target Version 7.7.0 => 7.8.0
2023-08-01 15:08 dpasukhi Target Version 7.8.0 => Unscheduled
2024-01-30 12:27 dpasukhi Note Added: 0115006
2024-01-30 12:32 dpasukhi Assigned To vmigunov => astromko
2024-02-07 15:32 dpasukhi Summary BRepOffset_Tool - Segmentation Fault => Modeling Algorithms - BRepOffset_Tool Segmentation Fault
2024-02-08 20:03 git Note Added: 0115057
2024-02-13 00:50 git Note Added: 0115073
2024-02-14 22:08 git Note Added: 0115089
2024-02-15 00:48 git Note Added: 0115091
2024-02-15 13:29 astromko Assigned To astromko => oan
2024-02-15 13:29 astromko Status assigned => resolved
2024-02-15 13:29 astromko Note Added: 0115094
2024-02-16 19:20 astromko Assigned To oan => akaftasev
2024-02-19 14:10 akaftasev Assigned To akaftasev => astromko
2024-02-19 14:10 akaftasev Status resolved => assigned
2024-02-19 14:10 akaftasev Note Added: 0115136
2024-02-19 14:11 akaftasev Note Edited: 0115136
2024-02-19 14:13 akaftasev Note Edited: 0115136
2024-02-22 16:52 git Note Added: 0115152
2024-02-23 18:06 astromko Assigned To astromko => akaftasev
2024-02-23 18:06 astromko Status assigned => resolved
2024-02-23 18:06 astromko Note Added: 0115162
2024-02-29 14:25 akaftasev Assigned To akaftasev => astromko
2024-02-29 14:25 akaftasev Status resolved => assigned
2024-02-29 14:25 akaftasev Note Added: 0115198
2024-02-29 15:56 git Note Added: 0115200
2024-02-29 17:00 astromko Assigned To astromko => akaftasev
2024-02-29 17:00 astromko Status assigned => resolved
2024-02-29 17:00 astromko Note Added: 0115202
2024-03-01 15:06 git Note Added: 0115209