From 1596e4b1fd8d45b354da4620f1cae942c616b163 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 dad0590..e629435 100644 --- a/runtime/reporter.go +++ b/runtime/reporter.go @@ -102,7 +102,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] } }