client: Detect invalid response message format #256

Open
opened 2025-12-28 18:07:35 +00:00 by sami · 0 comments
Owner

Originally created by @cthulhu-rider on GitHub (Dec 10, 2024).

currently, when Client receives protobuf message incompatible with the response structure, it returns invalid response signature. This happens because in this case proto decoder:

  • returns no error;
  • leaves decoded response untouched (empty)
  • sets unknown fields in the decoded response

Describe the solution you'd like

when Client receives response message having known fields with broken format (e.g. wrong type), return clear error on this

note: some fields can be just unsupported (old client, new server). I did not check is it easy to distinguish broken fields from unsupported ones or not, so be careful: unsupported fields must not be denied in general for forward compatibility

Describe alternatives you've considered

do nothing. Technically, there is definitely no valid response signature. But nobody will know what the actual problem is

Additional context

Client testing. Following snippet can also be useful:

func TestInvalidResponseFormat(t *testing.T) {
	m := timestamppb.Now()
	b, err := proto.Marshal(m)
	require.NoError(t, err)
	var resp protoobject.HeadResponse_Body
	require.Error(t, proto.Unmarshal(b, &resp), resp)
}
=== RUN   TestInvalidResponseFormat
        	Error:      	An error is expected but got nil.
        	Test:       	TestInvalidResponseFormat
        	Messages:   	{state:{NoUnkeyedLiterals:{} DoNotCompare:[] DoNotCopy:[] atomicMessageInfo:0xc0002222a0} sizeCache:0 unknownFields:[8 185 193 225 186 6 16 142 250 191 211 1] Head:<nil>}
Originally created by @cthulhu-rider on GitHub (Dec 10, 2024). ## Is your feature request related to a problem? Please describe. currently, when `Client` receives protobuf message incompatible with the response structure, it returns `invalid response signature`. This happens because in this case proto decoder: - returns no error; - leaves decoded response untouched (empty) - sets unknown fields in the decoded response ## Describe the solution you'd like when `Client` receives response message having known fields with broken format (e.g. wrong type), return clear error on this note: some fields can be just unsupported (old client, new server). I did not check is it easy to distinguish broken fields from unsupported ones or not, so be careful: unsupported fields must not be denied in general for forward compatibility ## Describe alternatives you've considered do nothing. Technically, there is definitely no valid `response signature`. But nobody will know what the actual problem is ## Additional context `Client` testing. Following snippet can also be useful: ```go func TestInvalidResponseFormat(t *testing.T) { m := timestamppb.Now() b, err := proto.Marshal(m) require.NoError(t, err) var resp protoobject.HeadResponse_Body require.Error(t, proto.Unmarshal(b, &resp), resp) } ``` ``` === RUN TestInvalidResponseFormat Error: An error is expected but got nil. Test: TestInvalidResponseFormat Messages: {state:{NoUnkeyedLiterals:{} DoNotCompare:[] DoNotCopy:[] atomicMessageInfo:0xc0002222a0} sizeCache:0 unknownFields:[8 185 193 225 186 6 16 142 250 191 211 1] Head:<nil>} ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
nspcc-dev/neofs-sdk-go#256
No description provided.