From de96c8e8e1426eceae20dc383e31a0d28b5634fd Mon Sep 17 00:00:00 2001 From: Filippo Valsorda Date: Sat, 29 Aug 2026 18:56:01 +0200 Subject: [PATCH] cmd/age: reject invalid UTF-8 terminal output Reported by Joe Doyle of Trail of Bits. --- cmd/age/age.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/age/age.go b/cmd/age/age.go index 71e5d9b..7766af3 100644 --- a/cmd/age/age.go +++ b/cmd/age/age.go @@ -19,6 +19,7 @@ import ( "slices" "strings" "unicode" + "unicode/utf8" "filippo.io/age" "filippo.io/age/agessh" @@ -295,7 +296,7 @@ func main() { // Buffer the output to check it's printable. out = buf defer func() { - if bytes.ContainsFunc(buf.Bytes(), func(r rune) bool { + if !utf8.Valid(buf.Bytes()) || bytes.ContainsFunc(buf.Bytes(), func(r rune) bool { return r != '\n' && r != '\r' && r != '\t' && unicode.IsControl(r) }) { errorWithHint("refusing to output binary to the terminal",