Repository navigation
fix(service-maker): validate buffer extraction before creating tensors - #114
Draft
chunlinl1980 wants to merge 2 commits into
Draft
chunlinl1980 wants to merge 2 commits into
chunlinl1980 wants to merge 2 commits into
Conversation
Check mapped surface size and filled batch bounds before indexing. Return None from Python when extraction fails, and document the contract with GPU regression coverage. Fixes #101 Signed-off-by: chunlinl <chunlinl@nvidia.com>
wyw1267
reviewed
Nov 4, 2026
| cuStatus = cuGraphicsEGLRegisterImage(&cuGrphRes, surface.mappedAddr.eglImage, CU_GRAPHICS_MAP_RESOURCE_FLAGS_NONE); | ||
| if (cuStatus != CUDA_SUCCESS) | ||
| g_printerr("EGL Reguster Image Failed\n"); | ||
| cuGraphicsResourceGetMappedEglFrame(&eglFrame, cuGrphRes, batchId, 0); |
Collaborator
There was a problem hiding this comment.
Hi @chunlinl1980 , the 3rd arg of this API is the array/cubemap index within the registered resource, not a batch index. Could you confirm the index should be 0 like nvinfer? Thanks
Collaborator
Author
There was a problem hiding this comment.
You're absolutely right, I've posted a new commit.
Use EGL image index zero rather than the DeepStream batch index. Check mapping, registration and frame layout before creating a tensor, retain the backing buffer, and synchronize and unregister CUDA resources before destroying the EGL image. Signed-off-by: chunlinl <chunlinl@nvidia.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #101.
Validate the mapped buffer size, surface list, batch capacity, and filled-frame count before accessing a surface. Return Python
Nonewhen extraction fails instead of creating a wrapper around a null tensor. RGB extraction remains supported; unsupported formats such as RGBA and NV12 returnNone.On the EGL path, use CUDA image index zero: the batch ID already selected the registered image. Check mapping/registration results and require a pitched, single-plane frame before accessing its pointer. Use the mapped frame dimensions and pitch. Retain the backing GstBuffer for tensor lifetime, and restore the extraction CUDA context for synchronization and unregistration before EGL image destruction. Restrict EGL mapping to its documented SURFACE_ARRAY memory type.
Update the C++ and Python API documentation and add six subprocess GPU regression cases covering RGB/RGBA/NV12 with single-frame and partially filled batches, empty/non-surface buffers, invalid batch IDs, and copying a retained RGB tensor after pipeline teardown.
Reason
The core indexed the surface array before validating its layout or batch ID. Failed extraction was then exposed to Python as a tensor whose methods could dereference null. Checking the filled-frame count also prevents returning tensors for unused batch slots.
Validation
bash ./build/build.sh --package)The earlier source4 smoke test passed against the installed SDK, not this source build, and does not satisfy the required source4 validation. The ARM EGL branch passed a syntax-only check with local CUDA headers and aarch64 enabled; this is not a Jetson build or runtime test. Jetson EGL runtime validation, including nonzero batch IDs and mapping/registration failure paths, remains outstanding. The installed SDK was not replaced. This PR remains a draft pending full validation.
Checklist
NVIDIA/DeepStream:develop.NVIDIA/DeepStream:develop.bash ./build/build.sh --packagecompleted successfully.deepstream-appon x86 or Jetson.git commit -s).