From 63c1734bb57fb6e5ae40e48113998fd5fc066118 Mon Sep 17 00:00:00 2001 From: Zettat123 Date: Tue, 28 Mar 2023 11:49:09 +0800 Subject: [PATCH] Fix potential log panic (#82) If a job uses a [reusable workflow](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-of-jobsjob_iduses), the job's steps sequence will be empty. But in log reporter, we don't check the length of `r.state.Steps`, which may cause panic. ``` go if v, ok := entry.Data["stepNumber"]; ok { if v, ok := v.(int); ok { step = r.state.Steps[v] } } ``` Reviewed-on: https://gitea.com/gitea/act_runner/pulls/82 Reviewed-by: Lunny Xiao Co-authored-by: Zettat123 Co-committed-by: Zettat123 --- runtime/reporter.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/reporter.go b/runtime/reporter.go index 544852a..51d5e59 100644 --- a/runtime/reporter.go +++ b/runtime/reporter.go @@ -99,7 +99,7 @@ func (r *Reporter) Fire(entry *log.Entry) error { var step *runnerv1.StepState if v, ok := entry.Data["stepNumber"]; ok { - if v, ok := v.(int); ok { + if v, ok := v.(int); ok && len(r.state.Steps) > v { step = r.state.Steps[v] } }