Skip to content

0001179: Fix null context crash in ShapeUpgrade_FaceDivide::Perform()#1203

Open
gsdali wants to merge 3 commits intoOpen-Cascade-SAS:IRfrom
gsdali:CR1179
Open

0001179: Fix null context crash in ShapeUpgrade_FaceDivide::Perform()#1203
gsdali wants to merge 3 commits intoOpen-Cascade-SAS:IRfrom
gsdali:CR1179

Conversation

@gsdali
Copy link
Copy Markdown

@gsdali gsdali commented Apr 16, 2026

Issue

Fixes #1179

Problem

ShapeUpgrade_FaceDivide::Perform() crashes with a null pointer dereference in SplitCurves() at Context()->Apply() because myContext is never initialized.

ShapeUpgrade_FaceDivide inherits from ShapeUpgrade_Tool, which does not allocate a default ShapeBuild_ReShape context. The sibling class ShapeUpgrade_ShapeDivide handles this correctly with lazy initialization in its own Perform():

// ShapeUpgrade_ShapeDivide::Perform() — line 120-121
if (newContext || myContext.IsNull())
    myContext = new ShapeBuild_ReShape;

But ShapeUpgrade_FaceDivide::Perform() has no such guard.

Crash details

Fix

Add lazy context initialization at the top of Perform(), matching the pattern used by ShapeUpgrade_ShapeDivide:

if (Context().IsNull())
    SetContext(new ShapeBuild_ReShape);

Verification

  • Single-threaded: was crashing, now passes (100 iterations)
  • Parallel (10 worker threads, 300 tasks/round, 10 rounds = 33,000 operations): was crashing 100%, now passes 5/5 runs
  • All 11 isolated operation groups pass, plus combined test

ShapeUpgrade_FaceDivide::Perform() crashes with a null pointer
dereference in SplitCurves() at Context()->Apply() because
myContext is never initialized.

Unlike ShapeUpgrade_ShapeDivide (which creates a default
ShapeBuild_ReShape context in its Perform()), FaceDivide inherits
directly from ShapeUpgrade_Tool which does not allocate a context.

The fix adds lazy context initialization at the top of Perform(),
matching the pattern used by ShapeUpgrade_ShapeDivide::Perform().

Crash reproduces both single-threaded and under concurrent execution
on Windows (MSVC 19.44) and macOS (Apple Clang 21).

Reproducer: https://github.com/gsdali/OCCTSwift/blob/main/Tests/occt_parallel_crash_portable.cpp
CI verification: https://github.com/gsdali/OCCTSwift/actions/runs/24509869728
gsdali added 2 commits April 17, 2026 10:27
QA DRAW command OCC1179 tests ShapeUpgrade_FaceDivide::Perform()
with no pre-set context, both single-threaded (10 iterations) and
parallel (300 concurrent tasks via OSD_Parallel::For).

Without the fix, the first call crashes with SIGSEGV at
SplitCurves() -> Context()->Apply() due to null myContext handle.

Tcl test: tests/bugs/heal/bug1179
DRAW command: OCC1179 (registered in QABugs_20.cxx)
Apply clang-format corrections and replace em-dash with ASCII hyphen
in code comment.
@dpasukhi
Copy link
Copy Markdown
Member

Dear @gsdali

Thank you for your patch. To proceed with integration, please complete signing CLA process:
The links: Contribution Guide
Or https://dev.opencascade.org/get_involved
Please validate the filled fields, all fields are requiered, only with exception if written (optional).

In case if you already have signed CLA, please share ID that OCCT team shared with your by email after accepting of CLA.

After CLA I will review your code and update the PR. I will clean up comments, remove the QA test and move that test into GTest(C++), not DRAW.

@dpasukhi dpasukhi added the 3. CLA waited User need to process with CLA before review or integration processes label Apr 17, 2026
@dpasukhi dpasukhi changed the base branch from master to IR April 17, 2026 06:37
@gsdali
Copy link
Copy Markdown
Author

gsdali commented Apr 17, 2026 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. CLA waited User need to process with CLA before review or integration processes

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Thread safety research under concurrent OCCT on arm64 macOS (8.0.0-rc4)

2 participants