This is an automated email from the ASF dual-hosted git repository.

alexstocks pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git


The following commit(s) were added to refs/heads/develop by this push:
     new fe230b9f5 fix: propagate encoding errors in marshalRequest (fixes 
#2517) (#2817)
fe230b9f5 is described below

commit fe230b9f56395191649929411ae45053d1ff59a4
Author: Lavi Khandelwal <[email protected]>
AuthorDate: Sat Apr 5 18:04:50 2025 +0530

    fix: propagate encoding errors in marshalRequest (fixes #2517) (#2817)
    
    * fix: propagate encoding errors in marshalRequest (fixes #2517)
    
    * lint fix
---
 protocol/dubbo/impl/hessian.go      |  4 +++-
 protocol/dubbo/impl/hessian_test.go | 44 +++++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/protocol/dubbo/impl/hessian.go b/protocol/dubbo/impl/hessian.go
index df90bd413..ad8d77353 100644
--- a/protocol/dubbo/impl/hessian.go
+++ b/protocol/dubbo/impl/hessian.go
@@ -136,7 +136,9 @@ func marshalRequest(encoder *hessian.Encoder, p 
DubboPackage) ([]byte, error) {
        }
        _ = encoder.Encode(types)
        for _, v := range args {
-               _ = encoder.Encode(v)
+               if e := encoder.Encode(v); e != nil {
+                       return nil, perrors.Wrapf(e, "failed to encode 
argument: %v", v)
+               }
        }
 
        request.Attachments[PATH_KEY] = service.Path
diff --git a/protocol/dubbo/impl/hessian_test.go 
b/protocol/dubbo/impl/hessian_test.go
index 0c824516b..203fe0ba5 100644
--- a/protocol/dubbo/impl/hessian_test.go
+++ b/protocol/dubbo/impl/hessian_test.go
@@ -22,6 +22,7 @@ import (
 )
 
 import (
+       "github.com/apache/dubbo-go-hessian2"
        "github.com/stretchr/testify/assert"
 )
 
@@ -58,3 +59,46 @@ func TestGetArgType(t *testing.T) {
                assert.Equal(t, dubboParam, getArgType(&Param{}))
        })
 }
+
+func TestMarshalRequestWithTypedNilPointer(t *testing.T) {
+       encoder := hessian.NewEncoder()
+       pkg := DubboPackage{
+               Service: Service{
+                       Path:    "test.Path",
+                       Version: "1.0.0",
+                       Method:  "Echo",
+               },
+               Body: &RequestPayload{
+                       Params: []interface{}{(*int32)(nil)},
+                       Attachments: map[string]interface{}{
+                               "key": "value",
+                       },
+               },
+       }
+
+       data, err := marshalRequest(encoder, pkg)
+       assert.NoError(t, err)
+       assert.NotNil(t, data)
+}
+
+func TestMarshalRequestWithNonNilPointer(t *testing.T) {
+       val := int32(42)
+       encoder := hessian.NewEncoder()
+       pkg := DubboPackage{
+               Service: Service{
+                       Path:    "test.Path",
+                       Version: "1.0.0",
+                       Method:  "Echo",
+               },
+               Body: &RequestPayload{
+                       Params: []interface{}{&val},
+                       Attachments: map[string]interface{}{
+                               "key": "value",
+                       },
+               },
+       }
+
+       data, err := marshalRequest(encoder, pkg)
+       assert.NoError(t, err)
+       assert.NotNil(t, data)
+}

Reply via email to