Skip to content

fix(examples): write triangle-headless PNG through os.Root - #363

Merged
kolkov merged 1 commit into
mainfrom
fix/lint-g703-triangle-headless
Oct 18, 2026
Merged

kolkov merged 1 commit into
mainfrom
fix/lint-g703-triangle-headless

Conversation

@kolkov

@kolkov kolkov commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

The Lint job fails on main and on every open PR. CI runs golangci-lint with version: latest, and the current release's gosec reports G703 (path traversal via taint analysis) for examples/triangle-headless/main.go:318. The example passes the path from os.Args to os.WriteFile. gosec deliberately does not treat the filepath.Clean already on that path as a sanitizer: Clean resolves .. instead of rejecting it.

The example now opens an os.Root on the target directory and writes the base name inside it, as gosec recommends. The PNG goes to the same place as before. I checked relative, nested, absolute and ./ paths, plus a missing directory, against the old os.WriteFile: the files land in the same places and a missing directory still fails. The write just can't leave that directory through .. or a symlink. The error from closing the root is returned instead of being dropped in a defer. No //nolint.

Verified on a clean checkout:

  • golangci-lint (latest config) 0 issues on windows, linux/amd64 and darwin/arm64;
  • gofmt and go mod tidy clean; builds for windows, linux/amd64 and darwin/arm64;
  • go test ./... passes;
  • go vet exactly as CI runs it (linux, without hal/vulkan/vk and hal/gles) is clean.

Once this is in, the open PRs pass Lint after a rebase.

The latest golangci-lint (gosec G703, path traversal via taint analysis)
flags os.WriteFile on the path taken from os.Args. filepath.Clean is not a
sanitizer for it: Clean resolves ".." instead of rejecting it. The Lint
job therefore fails on main and on every pull request.

Open an os.Root on the target directory and write the base name inside
it, as gosec recommends. The PNG lands in the same place as before, but
the write cannot leave that directory through ".." or a symlink. The
error from closing the root is returned too, not dropped in a defer.
@codecov

codecov Bot commented Oct 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@kolkov
kolkov merged commit 2fc93cb into main Oct 18, 2026
15 checks passed
@kolkov
kolkov deleted the fix/lint-g703-triangle-headless branch October 18, 2026 11:10
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.

1 participant