Skip to content

Modeling Data - Fix GeomTools_Curve2dSet/SurfaceSet null-handle Add()/Index() divergence from CurveSet - #1435

Open
gsdali wants to merge 1 commit into
Open-Cascade-SAS:masterfrom
gsdali:fix/geomtools-curve2dset-surfaceset-null-handle-add-index
Open

Modeling Data - Fix GeomTools_Curve2dSet/SurfaceSet null-handle Add()/Index() divergence from CurveSet#1435
gsdali wants to merge 1 commit into
Open-Cascade-SAS:masterfrom
gsdali:fix/geomtools-curve2dset-surfaceset-null-handle-add-index

Conversation

@gsdali

@gsdali gsdali commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Description of the change

GeomTools_CurveSet::Add guards a null Handle(Geom_Curve) and drops it (return (C.IsNull()) ? 0 : myMap.Add(C);). GeomTools_Curve2dSet::Add and GeomTools_SurfaceSet::Add do not: they accept
the null and hand back a valid-looking index, which later crashes Write() when it dereferences the
handle it was never checked against. Index() has the identical divergence one function down
(CurveSet::Index guards, the other two do not) — it does not crash, since
NCollection_IndexedMap::FindIndex only hashes/compares the handle's identity, but it silently
returns a bogus non-zero index for a handle that was never validly bound.

Adds the same guard CurveSet::Add/CurveSet::Index already have, to both methods on both sibling
classes — four one-line changes, matching the correct sibling rather than introducing a new pattern:

// GeomTools_Curve2dSet.cxx
int GeomTools_Curve2dSet::Add(const occ::handle<Geom2d_Curve>& S)
{
  return (S.IsNull()) ? 0 : myMap.Add(S);
}
...
int GeomTools_Curve2dSet::Index(const occ::handle<Geom2d_Curve>& S) const
{
  return (S.IsNull()) ? 0 : myMap.FindIndex(S);
}

// GeomTools_SurfaceSet.cxx
int GeomTools_SurfaceSet::Add(const occ::handle<Geom_Surface>& S)
{
  return (S.IsNull()) ? 0 : myMap.Add(S);
}
...
int GeomTools_SurfaceSet::Index(const occ::handle<Geom_Surface>& S) const
{
  return (S.IsNull()) ? 0 : myMap.FindIndex(S);
}

Related issue

Fixes #1434.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  1. Standalone repro (attached in GeomTools_Curve2dSet::Add / GeomTools_SurfaceSet::Add accept a null handle and defer the crash to Write(), unlike the CurveSet sibling #1434): Add(nullHandle) then Write() on GeomTools_Curve2dSet
    and GeomTools_SurfaceSet SIGSEGVs on stock master/V8_0_1; GeomTools_CurveSet does not,
    since its Add() already drops the null.
  2. Override-link (this repo's two changed files compiled standalone and linked ahead of the OCCT
    static archive, so the linker resolves these two TUs' symbols from the override): before the
    patch, Curve2dSet/SurfaceSet both accept the null (Add returns 1) and SIGSEGV in Write();
    after, all three classes' Add() return 0 and Write() completes normally on all three.
  3. Index() before the patch returns the same bogus 1 for Curve2dSet/SurfaceSet after adding a
    null handle; after, all three classes' Index() return 0, matching CurveSet::Index.
  4. A populated, all-valid-handle set is unaffected in either direction: Add/Index/Write/Read
    behavior for non-null handles is untouched by this change (the new branch is only taken when
    IsNull() is true).

Checklist:

  • My code follows the code style of this project
  • I have commented my code, particularly in hard-to-understand areas — N/A, both added checks
    mirror GeomTools_CurveSet's own existing, uncommented idiom line for line
  • My change requires a change to the documentation — N/A, no public API/behavior change beyond
    "does not crash, and reports the same index CurveSet already reports for a null handle"
  • I have added tests to cover my changes — regression coverage lives in the downstream Swift
    wrapper project (OCCTSwift), which found this crash through a null-handle-guard census; happy
    to add a GTest if maintainers point me at the right fixture convention for this area

@dpasukhi

dpasukhi commented Aug 10, 2026

Copy link
Copy Markdown
Member

Dear @gsdali please add GTest to cover your changes, you can follow the logic of all exited GTests.
Previously you already added them.

…ex null-handle handling

GeomTools_CurveSet::Add already guards a null Handle(Geom_Curve) and drops it
(returns 0). GeomTools_Curve2dSet::Add and GeomTools_SurfaceSet::Add do not:
they accept the null and return a valid-looking index, then Write() derefs
it unconditionally and crashes. Index() has the identical divergence (no
crash, but a bogus non-zero index for a handle that was never really bound).

Matches the sibling that is already correct.

Tests: added GeomTools_Curve2dSet_Test.cxx and GeomTools_SurfaceSet_Test.cxx in
src/ModelingData/TKGeomBase/GTests/, covering Add()/Index() with a null handle (must be
dropped/return 0, matching GeomTools_CurveSet), Write() after adding a null (must not crash), and
a valid-handle case as a control. Verified both ways: against the current pinned kernel (predates
this fix), Add(null) returns 1 (should be 0) and Write() SIGSEGVs; linked with the patched
translation units ahead of the archive, all 8 tests pass.
@gsdali
gsdali force-pushed the fix/geomtools-curve2dset-surfaceset-null-handle-add-index branch from b683221 to db31ec1 Compare August 11, 2026 00:00
@gsdali

gsdali commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

Thanks — pushed GTests.

GeomTools_Curve2dSet_Test.cxx and GeomTools_SurfaceSet_Test.cxx in src/ModelingData/TKGeomBase/GTests/, four cases each: Add()/Index() with a null handle (must drop it / return 0, matching GeomTools_CurveSet), Write() after adding a null (must not crash), and a valid-handle case as a control. Verified both directions: against the current pinned kernel (predates this fix), Add(null) returns 1 and Write() SIGSEGVs; linked with the patched translation units ahead of the archive, all 8 tests pass.

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

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

GeomTools_Curve2dSet::Add / GeomTools_SurfaceSet::Add accept a null handle and defer the crash to Write(), unlike the CurveSet sibling

2 participants