fix(device-plugin): validate slice bounds in GetMigUUIDFromSmiOutput - #2430
fix(device-plugin): validate slice bounds in GetMigUUIDFromSmiOutput#2430Nitish08-08 wants to merge 1 commit into
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Nitish08-08 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThe MIG UUID parser now validates SMI output before indexing fields. Malformed records produce warnings and are skipped. Table-driven tests cover valid extraction, mismatched UUIDs, invalid indices, malformed lines, and missing instances. ChangesMIG parser hardening
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@pkg/device-plugin/nvidiadevice/nvinternal/plugin/util_test.go`:
- Around line 993-998: Update the “MIG line without enough colons” fixture to
use a numeric device index while omitting the “UUID:” field, so parsing reaches
UUID-field validation and still expects no match. Keep the matching GPU UUID and
index unchanged, and ensure the test rejects truncated records accepted by the
parser.
In `@pkg/device-plugin/nvidiadevice/nvinternal/plugin/util.go`:
- Around line 178-183: Update the MIG output parsing around colonParts in
pkg/device-plugin/nvidiadevice/nvinternal/plugin/util.go:178-183 to extract and
validate the actual UUID field after “UUID:” (or require four colon-separated
fields and select the UUID field), rather than using the profile field. Update
the malformed fixture in
pkg/device-plugin/nvidiadevice/nvinternal/plugin/util_test.go:993-998 to use a
numeric device index with the UUID field missing, ensuring the test reaches UUID
validation.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 00257a19-255f-437e-b141-bc3b02a4681c
📒 Files selected for processing (2)
pkg/device-plugin/nvidiadevice/nvinternal/plugin/util.gopkg/device-plugin/nvidiadevice/nvinternal/plugin/util_test.go
| colonParts := strings.Split(val, ":") | ||
| if len(colonParts) < 3 { | ||
| klog.Warningf("unexpected MIG output format, missing colon fields: %q", val) | ||
| continue | ||
| } | ||
| outputStr := colonParts[2] |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Parse and test the actual UUID field.
The parser selects the MIG profile field instead of the UUID field. The malformed fixture also exits during device-index parsing, so it cannot detect this defect.
pkg/device-plugin/nvidiadevice/nvinternal/plugin/util.go#L178-L183: extract the value after"UUID:", or validate four colon fields and select the UUID field.pkg/device-plugin/nvidiadevice/nvinternal/plugin/util_test.go#L993-L998: use a numeric device index with a missing UUID field so the test reaches the UUID-field validation.
📍 Affects 2 files
pkg/device-plugin/nvidiadevice/nvinternal/plugin/util.go#L178-L183(this comment)pkg/device-plugin/nvidiadevice/nvinternal/plugin/util_test.go#L993-L998
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@pkg/device-plugin/nvidiadevice/nvinternal/plugin/util.go` around lines 178 -
183, Update the MIG output parsing around colonParts in
pkg/device-plugin/nvidiadevice/nvinternal/plugin/util.go:178-183 to extract and
validate the actual UUID field after “UUID:” (or require four colon-separated
fields and select the UUID field), rather than using the profile field. Update
the malformed fixture in
pkg/device-plugin/nvidiadevice/nvinternal/plugin/util_test.go:993-998 to use a
numeric device index with the UUID field missing, ensuring the test reaches UUID
validation.
Closes Project-HAMi#2359 GetMigUUIDFromSmiOutput indexes directly into strings.Split() results without checking length. Malformed nvidia-smi output missing the 'Device' delimiter or sufficient colon-separated fields causes an index out of range panic. Add length validation before each slice access and replace klog.Fatal with Warningf+continue so a single malformed line does not crash the device-plugin. Also add unit tests covering valid output, empty input, missing delimiters, non-numeric indices, and uuid mismatches. Signed-off-by: Nitish08-08 <nitishkumar805511@gmail.com> Signed-off-by: Nitish <nitishsahani0708@gmail.com>
5e83445 to
6d12a89
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
|
Already fixed in #2246 |
Closes #2359
GetMigUUIDFromSmiOutput indexes directly into strings.Split() results without checking length. Malformed nvidia-smi output missing the 'Device' delimiter or sufficient colon-separated fields causes an index out of range panic.
Add length validation before each slice access and replace klog.Fatal with Warningf+continue so a single malformed line does not crash the device-plugin.
Also add unit tests covering valid output, empty input, missing delimiters, non-numeric indices, and uuid mismatches.
What type of PR is this?
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?:
Summary by CodeRabbit
Bug Fixes
Tests