Skip to content

Conversation

@aarzilli
Copy link
Member

@aarzilli aarzilli commented Aug 4, 2025

When string Variables containing non-unicode strings are encoded into
json their value is changed, which leads to subtle bugs such as
described in issue #4072.

This CL addresses the problem by adding a new field to the api.Variable
struct that will be used to transport the variable's value for strings
that can not be unicode-encoded.

This is the best we can do without breaking backwards compatibility.

For our Go code the change is handled transparently by a
MarshalJSON/UnmarshalJSON on the api.Variable type.

Fixes #4072

var v2 *variableWithoutMarshaler = (*variableWithoutMarshaler)(v)
if v2.Kind == reflect.String && !utf8.ValidString(v2.Value) {
value := v2.Value
// Should we blot out the value with something obviously wrong? Like:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a bad idea.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I'm esitant about this is that by not doing it we do send a mangled string (if it is not representable in utf8), but only a little bit. So it's more backwards compatible. However it could also be valuable to make the problem more obvious.

You decide.

When string Variables containing non-unicode strings are encoded into
json their value is changed, which leads to subtle bugs such as
described in issue go-delve#4072.
This CL addresses the problem by adding a new field to the api.Variable
struct that will be used to transport the variable's value for strings
that can not be unicode-encoded.
This is the best we can do without breaking backwards compatibility.
For our Go code the change is handled transparently by a
MarshalJSON/UnmarshalJSON on the api.Variable type.

Fixes go-delve#4072
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.

Wrong handling of string([]byte) ?

2 participants