numpy::from_data calls vector::front and crashes (or has UB) when called with a scalar object

Open Beginner friendly
#526 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
84/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
cpp
Domain
backend

Research direction

Start in ndarray.cpp at from_data_impl, where shape.front() and strides.front() are used for potentially empty vectors. Reproduce or inspect the scalar-object path and verify that it no longer performs invalid access or crashes; run the repository’s relevant existing tests if available. Done means scalar from_data calls work without undefined behavior or the reported crash.

Written by the indexing model from the issue text.

Description

In ndarray.cpp, the function from_data_impl calls &shape.front() and &strides.front() for possibly empty vectors. This is, at best, undefined behavior. At worst, it triggers a crash (observed on Redhat/rocky 8&9, where I'm assuming boost::python packages were built with -D_GLIBCXX_DEBUG).

RECOMMEND: change &vec.front() to vec.data() to avoid UB and potential crashes.

Dominant language
C++
Stars
537
Forks
223
Avg merge
11h 22m
Merged PRs (30d)
2

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from boostorg/python

All issues in boostorg/python

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.