Skip to content

Validate COCO RLE masks before pixelwise decoding - #6565

Open
JanuszL wants to merge 5 commits into
NVIDIA:mainfrom
JanuszL:fix-coco-rle-mask-validation
Open

JanuszL wants to merge 5 commits into
NVIDIA:mainfrom
JanuszL:fix-coco-rle-mask-validation

Conversation

@JanuszL

@JanuszL JanuszL commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Validate COCO RLE masks before pixelwise decoding

Check RLE dimensions, run counts, and decoded coverage before copying
annotation data into image-sized buffers. Bound intermediate merged runs
and release temporary RLEs when validation fails.

Add CPU regressions for malformed and valid masks loaded from JSON and
preprocessed annotations, including compressed counts and zero-length
runs during label merging.

Category:

Bug fix (non-breaking change which fixes an issue)

Description:

Reject COCO RLE masks with inconsistent dimensions, excessive run counts,
or invalid decoded coverage before pixelwise processing. Check the merged
encoding size before writing into temporary buffers.

Tracks NVBug 7001099.

Additional information:

Affected modules and functionalities:

COCO reader pixelwise masks and annotation regression tests.

Key points relevant for the review:

Validation at the consumer covers JSON arrays, compressed counts, and
preprocessed annotations. Owning RLEMask containers free temporary
encodings on errors.

Tests:

  • Existing tests apply
  • New tests added
    • Python tests
    • GTests
    • Benchmark
    • Other
  • N/A

Added test_coco_invalid_rle_mask, test_coco_valid_rle_mask,
test_coco_rle_mask_merge, and test_coco_polygon_mask_ownership in
dali/test/python/reader/test_coco.py.
Existing malformed-bbox and filename tests also apply.

Checklist

Documentation

  • Existing documentation applies
  • Documentation updated
    • Docstring
    • Doxygen
    • RST
    • Jupyter
    • Other
  • N/A

DALI team only

Requirements

  • Implements new requirements
  • Affects existing requirements
  • N/A

REQ IDs: N/A

JIRA TASK: N/A

Check RLE dimensions, run counts, and decoded coverage before copying
annotation data into image-sized buffers. Bound intermediate merged runs
and release temporary RLEs when validation fails.

Add CPU regressions for malformed and valid masks loaded from JSON and
preprocessed annotations, including compressed counts and zero-length
runs during label merging.

Signed-off-by: Janusz Lisiecki <jlisiecki@nvidia.com>
@copy-pr-bot

copy-pr-bot Bot commented Oct 27, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@JanuszL JanuszL self-assigned this Oct 27, 2026
@JanuszL
JanuszL marked this pull request as ready for review October 27, 2026 17:33
@greptile-apps

greptile-apps Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The latest changes appear safe to merge; no new blocking failure was established.

Summary

The PR checks COCO RLE dimensions, run counts, and pixel coverage before copying masks into image-sized buffers. Temporary masks now use owning containers.

  • COCO pixelwise masks check each RLE against the image before decoding.
  • Label merging stops when its run list exceeds image-sized storage.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[JSON or saved annotations] --> B[Check each RLE mask]
  B -->|Invalid| C[Throw an input error]
  B -->|Valid| D[Create owned temporary masks]
  D --> E[Merge labels]
  E --> F[Check merged run count before writing]
  F --> G[Decode pixelwise mask]
Loading

Reviews (4) · Last reviewed commit: "Identify invalid COCO masks and simplify..." · Reviewed by Greptile

Comment thread dali/operators/reader/coco_reader_op.cc Outdated
Comment thread dali/operators/reader/coco_reader_op.cc Outdated
Replace scope guards and raw RLE containers with RLEMask ownership.
Pass temporary non-owning views to the C merge API and release replaced
label encodings through move assignment.

Cover single- and multiple-polygon masks from JSON and preprocessed
annotations alongside the existing malformed-RLE regressions.

Signed-off-by: Janusz Lisiecki <jlisiecki@nvidia.com>
Throw invalid_argument for malformed mask inputs and include actual and expected dimensions, run counts, and pixel coverage in diagnostics.

Assert Python ValueError and diagnostic values for JSON and preprocessed annotations, including runs that exceed the remaining image coverage.

Signed-off-by: Janusz Lisiecki <jlisiecki@nvidia.com>
@JanuszL

JanuszL commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

!build

@dali-automaton

Copy link
Copy Markdown
Collaborator

CI MESSAGE: [77139940]: BUILD STARTED

@dali-automaton

Copy link
Copy Markdown
Collaborator

CI MESSAGE: [77139940]: BUILD PASSED

Comment thread dali/operators/reader/coco_reader_op.cc Outdated
Comment thread dali/operators/reader/coco_reader_op.cc Outdated
Comment thread dali/operators/reader/coco_reader_op.cc Outdated
Signed-off-by: Janusz Lisiecki <jlisiecki@nvidia.com>
Signed-off-by: Janusz Lisiecki <jlisiecki@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants