mirror of
https://gitea.com/gitea/act_runner.git
synced 2026-05-28 10:23:06 +00:00
My builds kept flaking out with errors like `invalid format delimiter 'ghadelimiter_...' not found before end of file` or just strange failures in the complete job. After some digging I found an issue in `parseEnvFile` and have tested this fix against the test case presented.
- `parseEnvFile` reads `$GITHUB_ENV` / `$GITHUB_OUTPUT` with a `bufio.Scanner` using the default 64 KiB token size, and never checks `s.Err()`.
- Any action that writes a multi-line value with a single line >64 KiB silently aborts the scan with `bufio.ErrTooLong`, which surfaces as the misleading `"invalid format delimiter
'ghadelimiter_…' not found before end of file"`.
- Real-world trigger: `docker/build-push-action`'s `metadata` output embeds the full `GITHUB_EVENT_PATH` payload via buildx provenance; a long PR description (e.g. a Renovate dependency
table) puts the body field on one JSON-escaped line well past 64 KiB.
- Raise the scanner buffer to 1 MiB so realistic outputs parse.
### Reproduction
Test this in an action. This removes the `docker/build-push-action` aspect and reproduces it directly.
```yaml
jobs:
repro:
runs-on: ubuntu-latest
steps:
- id: big
run: |
{
echo 'value<<EOF'
head -c 70000 /dev/urandom | base64 -w0
echo
echo 'EOF'
} >> "$GITHUB_OUTPUT"
```
---------
Co-authored-by: Nicolas <bircni@icloud.com>
Co-authored-by: silverwind <me@silverwind.io>
Reviewed-on: https://gitea.com/gitea/runner/pulls/974
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-by: silverwind <2021+silverwind@noreply.gitea.com>
Co-authored-by: Jacob Alberty <jacob.alberty@gmail.com>
Co-committed-by: Jacob Alberty <jacob.alberty@gmail.com>
76 lines
2.3 KiB
Go
76 lines
2.3 KiB
Go
// 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<<EOF\nline1\nline2\nEOF\n"
|
|
require.NoError(t, os.WriteFile(envPath, []byte(content), 0o600))
|
|
|
|
env := map[string]string{}
|
|
require.NoError(t, parseEnvFile(e, envPath, &env)(context.Background()))
|
|
assert.Equal(t, "line1\nline2", env["FOO"])
|
|
}
|
|
|
|
func TestParseEnvFileLargeValueWithinLimit(t *testing.T) {
|
|
e, envPath := newTestHostEnv(t)
|
|
big := strings.Repeat("x", 2*1024*1024)
|
|
content := "FOO<<EOF\n" + big + "\nEOF\n"
|
|
require.NoError(t, os.WriteFile(envPath, []byte(content), 0o600))
|
|
|
|
env := map[string]string{}
|
|
require.NoError(t, parseEnvFile(e, envPath, &env)(context.Background()))
|
|
assert.Equal(t, big, env["FOO"])
|
|
}
|
|
|
|
func TestParseEnvFileLineExceedsBufferReportsScannerError(t *testing.T) {
|
|
e, envPath := newTestHostEnv(t)
|
|
tooBig := strings.Repeat("x", 17*1024*1024) // over the 16 MiB cap
|
|
content := "FOO<<EOF\n" + tooBig + "\nEOF\n"
|
|
require.NoError(t, os.WriteFile(envPath, []byte(content), 0o600))
|
|
|
|
env := map[string]string{}
|
|
err := parseEnvFile(e, envPath, &env)(context.Background())
|
|
require.ErrorIs(t, err, bufio.ErrTooLong)
|
|
assert.Contains(t, err.Error(), "reading env file")
|
|
}
|
|
|
|
func TestParseEnvFileMissingDelimiter(t *testing.T) {
|
|
e, envPath := newTestHostEnv(t)
|
|
require.NoError(t, os.WriteFile(envPath, []byte("FOO<<EOF\nline1\nline2\n"), 0o600))
|
|
|
|
env := map[string]string{}
|
|
err := parseEnvFile(e, envPath, &env)(context.Background())
|
|
require.Error(t, err)
|
|
assert.Contains(t, err.Error(), "delimiter")
|
|
}
|