diff --git a/act/container/parse_env_file.go b/act/container/parse_env_file.go index ec27807f..bfa261ca 100644 --- a/act/container/parse_env_file.go +++ b/act/container/parse_env_file.go @@ -29,6 +29,8 @@ func parseEnvFile(e Container, srcPath string, env *map[string]string) common.Ex return err } s := bufio.NewScanner(reader) + // Default 64 KiB max token size is too small for realistic env-file lines; allow up to 16 MiB. + s.Buffer(make([]byte, 0, 64*1024), 16*1024*1024) for s.Scan() { line := s.Text() singleLineEnv := strings.Index(line, "=") @@ -50,6 +52,9 @@ func parseEnvFile(e Container, srcPath string, env *map[string]string) common.Ex } multiLineEnvContent += content } + if err := s.Err(); err != nil { + return fmt.Errorf("reading env file: %w", err) + } if !delimiterFound { return fmt.Errorf("invalid format delimiter '%v' not found before end of file", multiLineEnvDelimiter) } @@ -58,6 +63,9 @@ func parseEnvFile(e Container, srcPath string, env *map[string]string) common.Ex return fmt.Errorf("invalid format '%v', expected a line with '=' or '<<'", line) } } + if err := s.Err(); err != nil { + return fmt.Errorf("reading env file: %w", err) + } env = &localEnv return nil } diff --git a/act/container/parse_env_file_test.go b/act/container/parse_env_file_test.go new file mode 100644 index 00000000..6a8525a6 --- /dev/null +++ b/act/container/parse_env_file_test.go @@ -0,0 +1,75 @@ +// Copyright 2026 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package container + +import ( + "bufio" + "context" + "os" + "path/filepath" + "strings" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func newTestHostEnv(t *testing.T) (*HostEnvironment, string) { + t.Helper() + e := &HostEnvironment{Path: t.TempDir()} + return e, filepath.Join(e.Path, "envfile") +} + +func TestParseEnvFileSingleLine(t *testing.T) { + e, envPath := newTestHostEnv(t) + require.NoError(t, os.WriteFile(envPath, []byte("FOO=bar\nBAZ=qux\n"), 0o600)) + + env := map[string]string{} + require.NoError(t, parseEnvFile(e, envPath, &env)(context.Background())) + assert.Equal(t, "bar", env["FOO"]) + assert.Equal(t, "qux", env["BAZ"]) +} + +func TestParseEnvFileMultiLine(t *testing.T) { + e, envPath := newTestHostEnv(t) + content := "FOO<