Skip to content

Fix gremlin-go negative BigInteger decoding and P.outside()#3522

Open
GumpacG wants to merge 1 commit into
apache:masterfrom
GumpacG:go-bugs
Open

Fix gremlin-go negative BigInteger decoding and P.outside()#3522
GumpacG wants to merge 1 commit into
apache:masterfrom
GumpacG:go-bugs

Conversation

@GumpacG

@GumpacG GumpacG commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

gremlin-go bug fixes

Two gremlin-go bugs introduced in 4.0.0-beta.2. Both made gremlin-go the only
GLV producing incorrect results; the fixes align it with gremlin-java,
gremlin-python, gremlin-dotnet, and gremlin-javascript.

1. Negative BigInteger / BigDecimal decoded incorrectly

Problem: readBigInt reconstructed negative two's-complement values with a bit
width one byte too wide ((len(b)+1)*8 instead of len(b)*8), so it subtracted a
power of two that was 256x too large. Positive values were unaffected. Negative
BigDecimal values were affected too, because their unscaled value decodes through
the same path. Go was the only GLV with this bug because it hand-rolls the
conversion (math/big has no signed-bytes constructor), while the other GLVs
delegate to a correct standard-library primitive.

Use case: a ledger service stores account balances as arbitrary-precision integers
so they never overflow. Account acct-1 is overdrawn by 500, stored as the
BigInteger -500.

Before:

r, _ := g.V("acct-1").Values("balance").Next()
balance := r.GetInterface() // *big.Int
// want:  -500
// got:   -16712180   (silently wrong, no error returned)

The application reads a balance of -16,712,180 for an account that is only 500
overdrawn. The error is silent, so it can flow into downstream calculations,
alerts, or stored data before anyone notices.

After:

r, _ := g.V("acct-1").Values("balance").Next()
balance := r.GetInterface() // *big.Int
// -500, matching the server and every other GLV

2. P.outside() generated invalid gremlin-lang

Problem: translatePValue list-wrapped the arguments of any multi-value predicate
except between and inside, but outside was omitted from that exclusion.
outside takes exactly two arguments in the grammar (like between/inside), so
they must be comma-separated, not wrapped in a list.

Use case: an anomaly-detection query finds sensor readings outside the normal
operating range of 18 to 65 (too cold or too hot).

Before:

readings, err := g.V().Has("temperature", gremlingo.P.Outside(18, 65)).ToList()
// generated gremlin-lang: g.V().has("temperature",outside([18,65]))
// err: server-side parse error - "outside([18,65])" is not valid gremlin-lang
// readings: nil

The query never runs. Because the identical query works from the Java, Python,
.NET, and JavaScript drivers, the failure looks like a server or environment
problem rather than a driver bug, and P.Outside is effectively unusable from Go.

After:

readings, err := g.V().Has("temperature", gremlingo.P.Outside(18, 65)).ToList()
// generated gremlin-lang: g.V().has("temperature",outside(18,65))
// err: nil
// readings: the out-of-range vertices, as expected

@codecov-commenter

codecov-commenter commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.46%. Comparing base (a28cd1f) to head (1e8487d).
⚠️ Report is 277 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3522      +/-   ##
============================================
+ Coverage     76.35%   76.46%   +0.10%     
- Complexity    13424    14272     +848     
============================================
  Files          1012     1036      +24     
  Lines         60341    64527    +4186     
  Branches       7075     7650     +575     
============================================
+ Hits          46076    49338    +3262     
- Misses        11548    12097     +549     
- Partials       2717     3092     +375     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

2 participants