Repository navigation
Reject invalid UTF-8 in trusted workflow blobs #1614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -124,12 +124,14 @@ def _remote_workflow(worktree: Path, branch: str, previous: Config | None) -> tu | |
| return previous, revision | ||
| shown = _proc.run( | ||
| ["git", "show", f"{revision}:workflow.toml"], | ||
| cwd=worktree, env_allowlist=worktree_mod.GIT_ENV, timeout=60, | ||
| cwd=worktree, env_allowlist=worktree_mod.GIT_ENV, timeout=60, preserve_newlines=True, encoding="utf-8", | ||
| ) | ||
| if shown.exit_code != 0: | ||
| raise ConfigError(f"cannot read {source}. {hint}") | ||
| try: | ||
| data = tomllib.loads(shown.stdout) | ||
| data = tomllib.loads(shown.stdout.encode("utf-8", errors="surrogateescape").decode("utf-8")) | ||
| except UnicodeDecodeError as exc: | ||
| raise ConfigError(f"{source}: {exc}") from exc | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Trusted-Git UTF-8 error omits the recovery hint Every other error from |
||
| except tomllib.TOMLDecodeError as exc: | ||
| raise ConfigError(f"{source}: invalid TOML: {exc}. {hint}") from None | ||
| try: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Surrogateescape round-trip is roundabout
With
preserve_newlines=True,_proc.rundecodes stdout witherrors="surrogateescape"(_proc.py:170). This change re-encodes that output to get the raw bytes back, then decodes it strictly. The result is correct: invalid bytes now raise instead of being silently replaced with U+FFFD as in the old text mode. But it depends on an internal detail of_proc.run's error handler, so it can break silently if that detail changes. The encoding is also passed in two places that must stay in sync. A simpler fix is to let_proc.rundecode strictly or return raw bytes, then pass the bytes totomllib.loads(raw.decode("utf-8")).