AlexStocks commented on code in PR #3812:
URL: https://github.com/apache/dubbo-go/pull/3812#discussion_r4596328656


##########
protocol/triple/triple_protocol/codec.go:
##########
@@ -340,10 +343,26 @@ func (c *protoWrapperCodec) Unmarshal(binary []byte, 
message any) error {
                return nil
        }
 
+       // Legacy gRPC-wire non-IDL responses used a one-argument request 
wrapper.
+       // Field 3 uniquely identifies that historical layout. Select by 
schema, never
+       // by a failed payload decode, then apply the same response allowlist.
+       if c.runtimeCodecs != nil {
+               var legacy interoperability.TripleRequestWrapper
+               if err := proto.Unmarshal(binary, &legacy); err == nil && 
len(legacy.Args) > 0 {

Review Comment:
   该问题在当前 head `3b50c6cb` 已修复,本线程可关闭。
   
   **改动事实**
   
   - `codec.go:347-349` 的注释已改为与实现一致的描述:「单参数 legacy 请求包装与响应包装的 payload 同处字段 2,字段 
3(argTypes/type)也为两者共用,因此无法标识任一布局」,原先「Select by schema, never by a failed 
payload decode / Field 3 uniquely identifies」的错误表述已删除。
   - 原先独立的 legacy 分支被合并进 response 解码路径,因此「带 `Data` 的正常响应先命中 legacy 分支、`// 
Response format` 分支仅对空 `Data` 可达」的错位不再存在——两个分支本就走同一个 `inner.Unmarshal`,现在只剩一条路径。
   - 新增 `protowire` 逐字段扫描(`codec.go:356-370`):用 
`ConsumeTag`/`ConsumeFieldValue` 推进,统计 `number == 2 && kind == 
protowire.BytesType` 的出现次数,第二次出现即返回 `wrapper codec: response contains multiple 
values`,从而避免 protobuf singular 字段语义把重复 payload 静默丢弃(只保留最后一个)。这一步是实质增强,不只是注释纠正。
   
   **测试覆盖**(我在提这条时要求的用例已补齐)
   
   `serialization_response_test.go:68` 的 
`TestConfiguredResponseRejectsRepeatedPayloads` 用 
`protowire.AppendTag`/`AppendBytes` 手工构造三种重复 
payload:`{a,b}`、`{nil,b}`、`{nil,nil}`,逐一断言报 `multiple values`,并用 
`require.Zero(t, probe.calls)` 证明**未进入 inner 解码**;另以 `[]byte{0xff}` 断言 `invalid 
response wrapper`。
   
   **本机验证**(go1.25.0,`-count=1`)
   
   ```
   === RUN   TestConfiguredResponseRejectsRepeatedPayloads
   --- PASS: TestConfiguredResponseRejectsRepeatedPayloads (0.00s)
   ok   dubbo.apache.org/dubbo-go/v3/protocol/triple/triple_protocol    0.021s
   ```
   
   结论:注释、实现、用例三者现已自洽,本线程按已修复处理。
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to