Skip to content

Python API: prevent string tensor constants to avoid crash#33659

Closed
amishijain123 wants to merge 2 commits intoopenvinotoolkit:masterfrom
amishijain123:fix-string-constant-segfault
Closed

Python API: prevent string tensor constants to avoid crash#33659
amishijain123 wants to merge 2 commits intoopenvinotoolkit:masterfrom
amishijain123:fix-string-constant-segfault

Conversation

@amishijain123
Copy link
Copy Markdown

### Description
This PR prevents crashes when creating Constant nodes from string tensors
in the OpenVINO Python API.

Previously, passing a NumPy array with string dtype (e.g. dtype=str)
to opset13.constant() resulted in a MemoryError or segmentation fault.

Now, such inputs are explicitly rejected with a clear and user-friendly
TypeError.

Changes

  • Added validation to block unsupported string tensor constants
  • Prevents MemoryError / segfault in Python API

Related issue

Fixes #23611

@amishijain123 amishijain123 requested a review from a team as a code owner January 17, 2026 06:32
@github-actions github-actions bot added the category: Python API OpenVINO Python bindings label Jan 17, 2026
@sys-openvino-ci sys-openvino-ci added the ExternalPR External contributor label Jan 17, 2026
@amishijain123
Copy link
Copy Markdown
Author

Hi maintainers,
Just a gentle follow-up on this PR.
Please let me know if any changes or updates are required from my side.
Thanks!

Copy link
Copy Markdown
Contributor

@p-wysocki p-wysocki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM as a workaround. Let's continue investigation in 180103, where we'll implement proper fix. For now let's avoid crashes.

_value, _shared_memory = _value.astype(_dtype), False

# Block unsupported string tensor constants
if isinstance(_value, np.ndarray) and _value.dtype.kind in ("U", "S", "O"):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if isinstance(_value, np.ndarray) and _value.dtype.kind in ("U", "S", "O"):
if isinstance(_value, np.ndarray) and _value.dtype.kind in ("U", "S", "O", "a"):

https://numpy.org/doc/stable/reference/arrays.dtypes.html

@p-wysocki
Copy link
Copy Markdown
Contributor

I see that another PR has been opened which actually implements creating string constants instead of not allowing them at all. #33574

@p-wysocki p-wysocki closed this Jan 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: Python API OpenVINO Python bindings ExternalPR External contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Good First Issue][Python API]: Create constant for string tensor and fix segfault

4 participants