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

Cole-Greer pushed a commit to branch 3.7-dev
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git


The following commit(s) were added to refs/heads/3.7-dev by this push:
     new c81f7c343f TINKERPOP-3277: Fix gremlin-go GraphBinary serialization of 
zero BigInteger/BigDecimal (#3540)
c81f7c343f is described below

commit c81f7c343f5c73bf98e066c4f9e3de54f2b09455
Author: Guian Gumpac <[email protected]>
AuthorDate: Thu Jul 23 12:54:34 2026 -0700

    TINKERPOP-3277: Fix gremlin-go GraphBinary serialization of zero 
BigInteger/BigDecimal (#3540)
    
    gremlin-go serialized a zero BigInteger as a GraphBinary length of 0 with 
no value
    bytes. Java's new BigInteger(new byte[0]) throws NumberFormatException, so 
a Java server
    could not read zero values sent by Go. The fix encodes zero as the 
canonical single 0x00
    byte (length 1), matching Java's BigInteger.toByteArray(). BigDecimal with 
a zero unscaled
    value is fixed transitively (it serializes its unscaled value as a 
BigInteger).
    
    Assisted-by: Kiro:claude-opus-4.8
---
 CHANGELOG.asciidoc                    |  1 +
 gremlin-go/driver/graphBinary.go      |  2 +-
 gremlin-go/driver/graphBinary_test.go | 28 ++++++++++++++++++++++++++++
 3 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index d6088e041e..f316877f25 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -39,6 +39,7 @@ 
image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 * Fixed `gremlin-python` `ProductiveByStrategy` to pass through the 
`productiveKeys` argument, which was previously accepted but never serialized 
to the server.
 * Deprecated `ProductiveByStrategy` which was introduced as a temporary way to 
mimic pre-3.5.0 null processing behavior.
 * Fixed `gremlin-python` GraphBinary serialization of 
`BigInteger`/`BigDecimal` negative boundary values (e.g. `-129`) that raised 
`OverflowError`.
+* Fixed `gremlin-go` GraphBinary serialization of zero 
`BigInteger`/`BigDecimal` values, which were encoded with zero length and 
rejected by Java servers.
 
 [[release-3-7-6]]
 === TinkerPop 3.7.6 (Release Date: April 1, 2026)
diff --git a/gremlin-go/driver/graphBinary.go b/gremlin-go/driver/graphBinary.go
index 59413cae2d..4af904c81b 100644
--- a/gremlin-go/driver/graphBinary.go
+++ b/gremlin-go/driver/graphBinary.go
@@ -318,7 +318,7 @@ func getSignedBytesFromBigInt(n *big.Int) []byte {
                }
                return b
        }
-       return []byte{}
+       return []byte{0}
 }
 
 // Format: {length}{value_0}...{value_n}
diff --git a/gremlin-go/driver/graphBinary_test.go 
b/gremlin-go/driver/graphBinary_test.go
index 4b0591cf90..e4aecb3db5 100644
--- a/gremlin-go/driver/graphBinary_test.go
+++ b/gremlin-go/driver/graphBinary_test.go
@@ -192,6 +192,34 @@ func TestGraphBinaryV1(t *testing.T) {
                        assert.Nil(t, err)
                        assert.Equal(t, new(big.Int).SetUint64(uint64(source)), 
res)
                })
+               t.Run("write bigInt zero exact bytes", func(t *testing.T) {
+                       var buffer bytes.Buffer
+                       buf, err := bigIntWriter(*big.NewInt(0), &buffer, nil)
+                       assert.Nil(t, err)
+                       assert.Equal(t, []byte{0x00, 0x00, 0x00, 0x01, 0x00}, 
buf)
+               })
+               t.Run("read-write bigInt zero", func(t *testing.T) {
+                       pos := 0
+                       var buffer bytes.Buffer
+                       source := big.NewInt(0)
+                       buf, err := bigIntWriter(*source, &buffer, nil)
+                       assert.Nil(t, err)
+                       res, err := readBigInt(&buf, &pos)
+                       assert.Nil(t, err)
+                       assert.Equal(t, 0, source.Cmp(res.(*big.Int)))
+               })
+               t.Run("read-write bigDecimal zero unscaled", func(t *testing.T) 
{
+                       pos := 0
+                       var buffer bytes.Buffer
+                       source := &BigDecimal{0, *big.NewInt(0)}
+                       buf, err := bigDecimalWriter(source, &buffer, nil)
+                       assert.Nil(t, err)
+                       res, err := readBigDecimal(&buf, &pos)
+                       assert.Nil(t, err)
+                       actual := res.(*BigDecimal)
+                       assert.Equal(t, source.Scale, actual.Scale)
+                       assert.Equal(t, 0, 
source.UnscaledValue.Cmp(&actual.UnscaledValue))
+               })
                t.Run("read-write list", func(t *testing.T) {
                        pos := 0
                        var buffer bytes.Buffer

Reply via email to