From cdc175b7b2f79bc68189194c5a897945a7aaa626 Mon Sep 17 00:00:00 2001 From: Matthew Sackman Date: Wed, 1 Apr 2026 11:51:02 +0100 Subject: [PATCH] protobuf/jsonpb: fix panic when decoding non-string bytes ``` exec cue eval schema.cue json+pb: data.json -- schema.cue -- t: bytes @protobuf(1, bytes) -- data.json -- {"t": 42} ``` This would panic because of a logic error in jsonpb/decoder.go Signed-off-by: Matthew Sackman Change-Id: Ie9c0bf1670a01f3223fb85d354a36ff1dfacedda Reviewed-on: https://cue.gerrithub.io/c/cue-lang/cue/+/1234625 TryBot-Result: CUEcueckoo Unity-Result: CUE porcuepine Reviewed-by: Roger Peppe --- encoding/protobuf/jsonpb/decoder.go | 2 +- .../protobuf/jsonpb/testdata/decoder/bytes_nonstring.txtar | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 encoding/protobuf/jsonpb/testdata/decoder/bytes_nonstring.txtar diff --git a/encoding/protobuf/jsonpb/decoder.go b/encoding/protobuf/jsonpb/decoder.go index 2ecba4954..af6e25bf4 100644 --- a/encoding/protobuf/jsonpb/decoder.go +++ b/encoding/protobuf/jsonpb/decoder.go @@ -209,7 +209,7 @@ func (r *rewriter) rewrite(schema cue.Value, expr ast.Expr) (x ast.Expr) { case cue.BytesKind: x, q, str := stringValue(expr) - if x == nil && q.IsDouble() { + if x == nil { break } diff --git a/encoding/protobuf/jsonpb/testdata/decoder/bytes_nonstring.txtar b/encoding/protobuf/jsonpb/testdata/decoder/bytes_nonstring.txtar new file mode 100644 index 000000000..8c8660422 --- /dev/null +++ b/encoding/protobuf/jsonpb/testdata/decoder/bytes_nonstring.txtar @@ -0,0 +1,6 @@ +-- schema.cue -- +b: [string]: bytes +-- int.cue -- +b: field: 42 +-- out/jsonpb/int.cue -- +b: field: 42 -- 2.51.2