Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,10 @@ jobs:
run: |
cd dart/packages/fory-test
dart test
- name: Run tests (Chrome)
run: |
cd dart/packages/fory
dart test -p chrome
- name: Run code analysis
run: |
cd dart/packages/fory-test
Expand Down
2 changes: 1 addition & 1 deletion dart/packages/fory/lib/src/buffer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ final class Buffer {
return;
}
final signed = BigInt.from(value);
final zigZag = ((signed << 1) ^ BigInt.from(value >> 63)) & _mask64Big;
final zigZag = ((signed << 1) ^ (signed >> 63)) & _mask64Big;
_writeVarUint64BigInt(zigZag);
}

Expand Down
2 changes: 1 addition & 1 deletion dart/packages/fory/lib/src/codegen/generated_support.dart
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ final class GeneratedWriteCursor {
}
final signed = BigInt.from(value);
final zigZag =
((signed << 1) ^ BigInt.from(value >> 63)) & _generatedCursorMask64Big;
((signed << 1) ^ (signed >> 63)) & _generatedCursorMask64Big;
_writeVarUint64BigInt(zigZag);
}

Expand Down
25 changes: 25 additions & 0 deletions dart/packages/fory/test/buffer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,31 @@ void main() {
}
});

test('varint64 round-trips positive values >= 2^31 (web zig-zag regression)', () {
const cases = <int>[
2147483648, // 2^31 — first value that triggers 32-bit sign confusion
3000000000,
4294967295, // 2^32 - 1
0x200000000, // 2^33
1 << 34,
1 << 42,
1 << 50,
0x7fffffffffffffff, // i64::MAX
];
for (final value in cases) {
final buffer = Buffer();
buffer.writeVarInt64(value);
final readBuffer = Buffer.wrap(buffer.toBytes());
final decoded = readBuffer.readVarInt64();
expect(
decoded,
equals(value),
reason: 'writeVarInt64($value) round-tripped to $decoded',
);
}
},
);

test('round-trips tagged int64 boundary values with Java-aligned lengths',
() {
const cases = <({int bytes, int value})>[
Expand Down
Loading