The GitHub Actions job "Publish Fory Java Snapshot" on fory.git/main has 
succeeded.
Run started by GitHub user chaokunyang (triggered by chaokunyang).

Head commit for run:
88a80385592779fff335495faefe79df86dfef53 / Jonathan Yoder <[email protected]>
fix(go): reference tracking fails when >127 objects serialized (#3086)

## What does this PR do?

Fixes reference tracking bug that causes deserialization to fail with
hash mismatch errors when more than 127 objects are serialized with
reference tracking enabled.

## Root Cause

The check `if int8(refID) < NotNullValueFlag` in multiple files causes
integer overflow when `refID >= 128`:

```go
// BEFORE (buggy):
if int8(refID) < NotNullValueFlag {
```

- `int8(128)` = `-128` (two's complement overflow)
- `-128 < -1` (NotNullValueFlag) = `TRUE` (incorrectly!)

This causes the code to incorrectly enter the "reference found" branch,
corrupting buffer positions and causing hash mismatches.

## Fix

Replace int8 cast with int32 comparison:

```go
// AFTER (fixed):
if refID < int32(NotNullValueFlag) {
```

Since `refID` is already `int32` (returned from `TryPreserveRefId`), and
the flag constants are small negative int8 values that correctly
sign-extend to int32, this comparison is type-safe and avoids
truncation.

## Files Changed

- `array.go` (1 occurrence)
- `map.go` (3 occurrences)
- `pointer.go` (2 occurrences)
- `reader.go` (7 occurrences)
- `serializer.go` (1 occurrence)
- `set.go` (4 occurrences)
- `slice.go` (1 occurrence)
- `slice_dyn.go` (4 occurrences)
- `struct.go` (2 occurrences)

## Testing

Added regression test `TestRefTrackingLargeCount` in
`ref_resolver_test.go` that verifies serialization/deserialization works
correctly with 127, 128, and 200 items.

All existing tests pass.

## Related Issues

Closes #3085

## Checklist

- [x] I have read the [contributing guidelines](../CONTRIBUTING.md)
- [x] I have added tests that prove my fix is effective
- [x] All new and existing tests pass locally with my changes

Report URL: https://github.com/apache/fory/actions/runs/20490973459

With regards,
GitHub Actions via GitBox


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

Reply via email to