Skip to content

getSensorsDataBatch: segfault from uninitialized pointer and wrong array indexing #31

Description

@TimGameDev

Preliminary Checks

  • This issue is not a duplicate. Before opening a new issue, please search existing issues.
  • This issue is not a question, feature request, or anything other than a bug report directly related to this project.

Description

ZEDController::getSensorsDataBatch() has two bugs that cause a segfault on the first call.

Steps to Reproduce

Bug 1: memset on uninitialized pointer

https://github.com/stereolabs/zed-c-api/blob/main/src/ZEDController.cpp#L640

// ZEDController.cpp line 640
memset(*data, 0, sizeof(SL_SensorsData) * size);

data is an output parameter (SL_SensorsData**). *data is uninitialized — writes to garbage address → SIGSEGV.

Bug 2: Wrong array indexing

https://github.com/stereolabs/zed-c-api/blob/main/src/ZEDController.cpp#L645

// ZEDController.cpp line 645
SL_SensorsData* sensorData = data[i];

data is a pointer to one pointer, not an array of pointers. data[i] for i > 0 reads out of bounds.

Additional: inner loop variable shadowing

https://github.com/stereolabs/zed-c-api/blob/main/src/ZEDController.cpp#L642
https://github.com/stereolabs/zed-c-api/blob/main/src/ZEDController.cpp#L674
The covariance copy loop at line 674 reuses the outer loop variable i:

for (int i = 0; i < size; i++) {           // outer
    for (int i = 0; i < 9; i++) { ... }    // shadows outer i
}

Expected Result

no crashes

Actual Result

SIGSEGV

ZED Camera model

ZED

Environment

ZED SDK 5.3.1, zed-c-api main (751d26f), Jetson Orin NX, JetPack 6.2.2

Anything else?

No response

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions