Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python interface to Part can be used to crash the application #13208

Closed
2 tasks done
bgbsww opened this issue Mar 28, 2024 · 1 comment · Fixed by #13675
Closed
2 tasks done

Python interface to Part can be used to crash the application #13208

bgbsww opened this issue Mar 28, 2024 · 1 comment · Fixed by #13675
Labels
Coding: Python Coding issue related to Python Crash For issues describing crashes or PRs fixing one WB Part Related to the Part Workbench

Comments

@bgbsww
Copy link
Contributor

bgbsww commented Mar 28, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Problem description

import Part
box = Part.makeBox(1,2,3)
cs = Part.CompSolid()
#cs.add(box)   # This will crash the app
comp = Part.Compound()
#cs.add(box)   # Or this
shell = Part.Shell()
shell.add(box.Faces[0])  # Or this.

The issue here is that it is possible to create initialized Python Objects with no OCCT shapes defined inside them (null), and then to call OCCT with that null shape pointer leading to the crash. The solutions could be: add defense c++ code inside the add() methods that checks to see if there is a shape and raises an exception, or to put dummy shapes in the Python Objects ( probably bad side effects ), or to block the use of the empty constructor ( tricky, might break existing code or addons ).

Also, there may be other methods that make the invalid assumption that there is a shape, and other Part object types like Wire and BuildPlateSurface. This needs a full survey to locate the affected code, at which point the changes should be straightorward.

Full version info

At least 0.20.2, 0.21.0, 0.21.1, current daily, current weekly, and builds from the HEAD.  Probably every version of FC.

Subproject(s) affected?

Part

Anything else?

Wish I wasn't busy with Toponaming to hunt this down. It is a good, easy intro to coding the C++ to Python interface.

Code of Conduct

  • I agree to follow this project's Code of Conduct
@maxwxyz maxwxyz added WB Part Related to the Part Workbench Crash For issues describing crashes or PRs fixing one Coding: Python Coding issue related to Python labels Mar 28, 2024
wwmayer added a commit to wwmayer/FreeCAD that referenced this issue Apr 27, 2024
Creating a shape with Part.CompSolid(), Part.Compound() or Part.Shell() is a null shape. In order to allow to append sub-shapes with the add()
method a valid shape must be created beforehand.

This fixes FreeCAD#13208
@wwmayer
Copy link
Contributor

wwmayer commented Apr 27, 2024

#13675

yorikvanhavre pushed a commit that referenced this issue May 6, 2024
Creating a shape with Part.CompSolid(), Part.Compound() or Part.Shell() is a null shape. In order to allow to append sub-shapes with the add()
method a valid shape must be created beforehand.

This fixes #13208
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Coding: Python Coding issue related to Python Crash For issues describing crashes or PRs fixing one WB Part Related to the Part Workbench
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants