Skip to content

[BUG] Undefined behavior in nvdsvideotemplate handling custom library properties string #64

Description

@CristiFati

nvdsvideotemplate (gst_nvdsvideotemplate_get_property) gets the custom library string properties by calling QueryProperties (returns a char* which is a string pointer rather than a pointer to an (unsigned) integer).

Then at NVIDIA/DeepStream - gstnvdsvideotemplate.cpp:625 it deallocates it: delete str; when it should be delete[] str;. That's Undefined Behavior, although it's known to work.

While we're at it, I think DSCustomLibraryBase::QueryProperties() (or from parent interface) should contain some doc or comment mentioning:

  • The returned string is deallocated by videotemplate
  • The deallocator used (in order to create the string with the appropriate allocator)

Initially I was returning the contents of a custom library class member, and that triggered gst-inspect-1.0 to segfault. With new[] or strdup (I chose the former) it no longer segfaults, but it's still incorrect.

Steps/Code to reproduce bug

The issue has no observable output (without using debug/profile tools), so using the first (wrong) variant that I had:

  1. Create a minimal custom library with e.g.:
    const char CustomLib::m_member[] = "dummy\n";
    
    char* CustomLib::QueryProperties() {
        return const_cast<char*> m_member;  // !nullptr
    }
  2. make
  3. NVDS_CUSTOMLIB="path/to/libcustomlib.so" gst-inspect-1.0 nvdsvideotemplate

Expected behavior
The output should contain the string, instead of segfaulting.

Environment details (please complete the following information):
N/A. I used a NVidia DS container.

Additional context
N/A

Might also apply to others (audiotemplate?).


By submitting this issue, you agree to follow our code of conduct and our contribution guidelines.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions