Skip to content

fix(alluxio): avoid index out of range in MasterPodName - #6284

Open
bhavishyajain545 wants to merge 1 commit into
fluid-cloudnative:masterfrom
bhavishyajain545:fix/alluxio-master-pod-name-bounds
Open

bhavishyajain545 wants to merge 1 commit into
fluid-cloudnative:masterfrom
bhavishyajain545:fix/alluxio-master-pod-name-bounds

Conversation

@bhavishyajain545

Copy link
Copy Markdown

Ⅰ. Describe what this PR does

AlluxioFileUtils.MasterPodName() parses the output of alluxio fsadmin report. It reads str[1] after checking len(str) < 1, and data[2] after checking len(data) < 2:

str := strings.Split(stdout, "\n")
if len(str) < 1 { ... return error }

data := strings.Fields(str[1])
if len(data) < 2 { ... return error }
address := strings.Split(data[2], ":")[0]

strings.Split never 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, or Master Address: without a value), the function panics with index out of range instead of returning the error it was written to return. MasterPodName() is called from generateDataBackupValueFile in pkg/ddc/alluxio/backup_data.go.

This PR checks for the lengths that are actually indexed (< 2 and < 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 report and index out of range and 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

go test -gcflags=all=-l ./pkg/ddc/alluxio/operations/ -run TestAlluxioFileUtils_MasterPodName

On master the new cases fail with panic: runtime error: index out of range [1] with length 1 at base.go:487. With the fix the whole pkg/ddc/alluxio/operations package 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.

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>
@sonarqubecloud

Copy link
Copy Markdown

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 cheyang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) and GetMountedAlluxioPaths (base.go:356) index fields[2] after strings.Fields(line) with no length check at all, so any short line in alluxio fs mount output 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 passes len(data) < 3 and data[2] is returned as the master address (e.g. Rpc Port: 19998 yields "19998"), which then feeds getMasterPod in generateDataBackupValueFile and 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: require data[0] == "Master" && data[1] == "Address:" before trusting data[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-existing get wrong result when using command %v message, 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.

@bhavishyajain545

Copy link
Copy Markdown
Author

Thanks for the detailed review. I opened #6285 for the unguarded fields[2] in IsMounted and GetMountedAlluxioPaths. I left the content check of the Master Address: line and the stdout in the parse error out of it; I can send those separately if you want them.

@codecov

codecov Bot commented Nov 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.16%. Comparing base (253f6bb) to head (2796b35).
⚠️ Report is 2 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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