Repository navigation
fix(alluxio): avoid index out of range in MasterPodName - #6284
bhavishyajain545 wants to merge 1 commit into
Conversation
MasterPodName read str[1] after checking len(str) < 1 and data[2] after checking len(data) < 2, so output of alluxio fsadmin report without the master address on its second line caused a panic instead of the intended error. Check for the lengths that are actually indexed. Signed-off-by: Bhavishya Jain <65864699+bhavishyajain545@users.noreply.github.com>
|
There was a problem hiding this comment.
🟢 Approval recommended
There are no active review issues for the change intended to prevent panics when parsing incomplete Alluxio command output.
No open issues 🎉
What changed in this PR
This PR prevents index-out-of-range panics in Alluxio’s MasterPodName(), which is used during data-backup setup, by returning errors for incomplete command output.
Changes:
- Corrects length checks before accessing the second output line and third field.
- Adds four regression cases covering empty or incomplete output while preserving existing valid-output behavior.
| File | Description |
|---|---|
pkg/ddc/alluxio/operations/base.go |
Fixes bounds checks when parsing the master address. |
pkg/ddc/alluxio/operations/base_test.go |
Adds four malformed-output cases that must return errors. |
Review effort: Balanced
cheyang
left a comment
There was a problem hiding this comment.
Both of us independently reproduced the premise on the merge-base — MasterPodName panics with index out of range when alluxio fsadmin report succeeds but prints malformed output (the len(str) < 1 guard is dead code and len(data) < 2 under-guards the data[2] index) — and both verified the fix at head: the new malformed-output cases return clean errors, the whole pkg/ddc/alluxio/operations package passes, and differential runs show every input that did not panic before behaves byte-identically after the change. The tightened guards reject exactly the inputs that panicked on base, so this is a strict panic→error conversion with no regression surface; the CI rollup is green at head. No PR-introduced issues were found — all four recorded findings are pre-existing and non-blocking. There was no meaningful disagreement between the reviewers (every finding survived cross-critique confirmed), and Reviewer C (Copilot) reviewed this head with no findings. Worth a follow-up tracking issue rather than this PR: the same unguarded fields[2] indexing in IsMounted/GetMountedAlluxioPaths (base.go:323/356), the shape-only validation that accepts any ≥3-field second line as the master address, and the parse-failure error message that omits the received stdout.
Next round
[MUST] (none — merge is not gated on any finding)
[SHOULD] File a follow-up issue covering the sibling unguarded fields[2] indexing in IsMounted/GetMountedAlluxioPaths and the lenient MasterPodName parse; optionally append a truncated stdout to the parse-failure error message.
[Filed] (none yet)
Non-blocking observations (3) — not part of this round's ask; fix now, follow up, or file an issue as you see fit
- pkg/ddc/alluxio/operations/base.go:323 [minor] — pre-existing, not introduced by this PR — Same panic class unguarded in IsMounted / GetMountedAlluxioPaths
F2 (consensus: found by Claude, confirmed by Codex's cross-critique): the same defect class this PR fixes remains in two sibling functions in the same file —IsMounted(base.go:323) andGetMountedAlluxioPaths(base.go:356) indexfields[2]afterstrings.Fields(line)with no length check at all, so any short line inalluxio fs mountoutput panics exactly like MasterPodName did, including the trailing empty element that\n-terminated stdout always yields. The existing IsMounted test mock has no trailing newline, which is why the suite never trips it. Pre-existing on merge-base and untouched by this PR's 2-line diff — does not gate this PR; recommend a follow-up issue (or a follow-up PR mirroring this one) rather than expanding scope here. - pkg/ddc/alluxio/operations/base.go:488 [minor] — pre-existing, not introduced by this PR — MasterPodName validates shape but not content: any >=3-field second line is accepted as the master address
F3 (consensus: found by Codex, confirmed by Claude's cross-critique with an independent canary): the guards check only the shape of the second line, not its content — any second line with >= 3 whitespace-separated fields passeslen(data) < 3anddata[2]is returned as the master address (e.g.Rpc Port: 19998yields "19998"), which then feedsgetMasterPodingenerateDataBackupValueFileand fails far from the real cause. Pre-existing: the canary observes address="19998" byte-identically on base and head, so this PR neither introduces nor worsens it. Cheap follow-up hardening: requiredata[0] == "Master" && data[1] == "Address:"before trustingdata[2]. Out of scope for this PR. - pkg/ddc/alluxio/operations/base.go:485 [nit] — pre-existing, not introduced by this PR — Parse-failure error message omits the offending stdout
F4 (consensus, independent convergence — Claude F3 = Codex F2): both malformed-output error paths reuse the pre-existingget wrong result when using command %vmessage, which records the (redacted) command but not the received stdout, so an operator hitting an fsadmin report format deviation cannot see what was actually returned — notably asymmetric with the exec-failure path a few lines above, which does log stdout/stderr. Pre-existing message pattern this PR correctly reuses; optional polish: append a truncated stdout to the message.
Verified review delta
- F1: fixed (preexisting)
- F2: open (preexisting)
- F3: open (preexisting)
- F4: open (preexisting)
Code: clear. CI: success; attribution: unknown. Required CI checks still apply.
|
Thanks for the detailed review. I opened #6285 for the unguarded |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #6284 +/- ##
==========================================
+ Coverage 66.13% 66.16% +0.02%
==========================================
Files 486 486
Lines 34616 34616
==========================================
+ Hits 22894 22902 +8
+ Misses 9964 9958 -6
+ Partials 1758 1756 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|



Ⅰ. Describe what this PR does
AlluxioFileUtils.MasterPodName()parses the output ofalluxio fsadmin report. It readsstr[1]after checkinglen(str) < 1, anddata[2]after checkinglen(data) < 2:strings.Splitnever returns an empty slice, so the first check never fires, and the second one lets a line with exactly two fields through. When the command succeeds but its output does not have the master address on the second line (empty output, a single line, orMaster Address:without a value), the function panics withindex out of rangeinstead of returning the error it was written to return.MasterPodName()is called fromgenerateDataBackupValueFileinpkg/ddc/alluxio/backup_data.go.This PR checks for the lengths that are actually indexed (
< 2and< 3). Output in the expected format is handled as before.Ⅱ. Does this pull request fix one issue?
NONE. I found this by reading the code, not on a running cluster. I searched issues and PRs for
MasterPodName,fsadmin reportandindex out of rangeand found nothing for it. #5984 adds a comment above the same test function; this PR only appends cases at the end of the function body.Ⅲ. List the added test cases (unit test/integration test) if any, please explain if no tests are needed.
Four unexpected-output cases added to
TestAlluxioFileUtils_MasterPodName(empty output, summary line only, empty second line,Master Address:without a value). Each must return an error.Ⅳ. Describe how to verify it
On
masterthe new cases fail withpanic: runtime error: index out of range [1] with length 1atbase.go:487. With the fix the wholepkg/ddc/alluxio/operationspackage passes locally. I did not run the linter or e2e locally.Ⅴ. Special notes for reviews
Disclosure: I used an AI assistant to help find and write this change. I have read and tested it myself and will answer review comments.