Skip to content

Commit

Permalink
Add dimension check in ssd_random_crop (#5240)
Browse files Browse the repository at this point in the history
ssd_random_crop wasn't checking dimensions of bboxes argument, leading to out of bounds memory accesses. In this PR I add this check and adjust an invalid checkpointing test.

Signed-off-by: Szymon Karpiński <skarpinski@nvidia.com>
Co-authored-by: Michał Zientkiewicz <mzient@gmail.com>
  • Loading branch information
szkarpinski and mzient authored Dec 15, 2023
1 parent 27ba04c commit dd19994
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions dali/operators/ssd/random_crop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ void SSDRandomCrop<CPUBackend>::RunImpl(SampleWorkspace &ws) {
int sample = ws.data_idx();

auto N = bboxes.dim(0);
DALI_ENFORCE(bboxes.ndim() == 2 && bboxes.dim(1) == 4,
"The second dimension of the bounding box tensor should be 4.");

const float* bbox_data = bboxes.data<float>();

const int* label_data = labels.data<int>();
Expand Down
2 changes: 1 addition & 1 deletion dali/test/python/checkpointing/test_dali_checkpointing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ def test_ssd_random_crop():
@pipeline_def
def pipeline():
data = fn.random.uniform(shape=(100, 100), dtype=types.DALIDataType.UINT8)
bbox = fn.random.uniform(shape=(4,), range=[0, 100], dtype=types.DALIDataType.FLOAT)
bbox = fn.random.uniform(shape=(7, 4), range=[0, 100], dtype=types.DALIDataType.FLOAT)
labels = fn.random.uniform(shape=(1,), dtype=types.DALIDataType.INT32)
return fn.ssd_random_crop(data, bbox, labels, device="cpu")[0]

Expand Down

0 comments on commit dd19994

Please sign in to comment.