From c7c0f868e5ce974a705a3444fde74c35bf0352b6 Mon Sep 17 00:00:00 2001 From: ayush00git Date: Tue, 21 Apr 2026 18:47:41 +0530 Subject: [PATCH 1/4] fix(dart): use BigInt for proper dart web truncation --- dart/packages/fory/lib/src/buffer.dart | 2 +- dart/packages/fory/lib/src/codegen/generated_support.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dart/packages/fory/lib/src/buffer.dart b/dart/packages/fory/lib/src/buffer.dart index ee1cdb49a7..03a33433de 100644 --- a/dart/packages/fory/lib/src/buffer.dart +++ b/dart/packages/fory/lib/src/buffer.dart @@ -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); } diff --git a/dart/packages/fory/lib/src/codegen/generated_support.dart b/dart/packages/fory/lib/src/codegen/generated_support.dart index d22d4f135b..f43a4fd5d6 100644 --- a/dart/packages/fory/lib/src/codegen/generated_support.dart +++ b/dart/packages/fory/lib/src/codegen/generated_support.dart @@ -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); } From 8cce6fc0ff13a8cee9eeeaca757200e2c84f02a1 Mon Sep 17 00:00:00 2001 From: ayush00git Date: Tue, 21 Apr 2026 23:12:05 +0530 Subject: [PATCH 2/4] feat: added regression test --- dart/packages/fory/test/buffer_test.dart | 30 ++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/dart/packages/fory/test/buffer_test.dart b/dart/packages/fory/test/buffer_test.dart index 4c972e5a9b..63bb2c163a 100644 --- a/dart/packages/fory/test/buffer_test.dart +++ b/dart/packages/fory/test/buffer_test.dart @@ -263,6 +263,36 @@ void main() { } }); + // Regression: Dart Web's `int >> 63` truncates to 32 bits, turning positive + // values >= 2^31 into -1 and corrupting the zig-zag sign bit. The fix uses + // `BigInt >> 63` in the web fallback path. + test( + 'varint64 round-trips positive values >= 2^31 (web zig-zag regression)', + () { + const cases = [ + 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})>[ From 64af05a8636eaa36f55eb123a63f08d5cef9ff1b Mon Sep 17 00:00:00 2001 From: ayush00git Date: Wed, 22 Apr 2026 00:03:15 +0530 Subject: [PATCH 3/4] fix: refactor comments --- dart/packages/fory/test/buffer_test.dart | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/dart/packages/fory/test/buffer_test.dart b/dart/packages/fory/test/buffer_test.dart index 63bb2c163a..0927c333d5 100644 --- a/dart/packages/fory/test/buffer_test.dart +++ b/dart/packages/fory/test/buffer_test.dart @@ -263,12 +263,7 @@ void main() { } }); - // Regression: Dart Web's `int >> 63` truncates to 32 bits, turning positive - // values >= 2^31 into -1 and corrupting the zig-zag sign bit. The fix uses - // `BigInt >> 63` in the web fallback path. - test( - 'varint64 round-trips positive values >= 2^31 (web zig-zag regression)', - () { + test('varint64 round-trips positive values >= 2^31 (web zig-zag regression)', () { const cases = [ 2147483648, // 2^31 — first value that triggers 32-bit sign confusion 3000000000, From f583c3dce49fb78266ca51887605796f62f73ce0 Mon Sep 17 00:00:00 2001 From: ayush00git Date: Wed, 22 Apr 2026 10:15:41 +0530 Subject: [PATCH 4/4] feat: added dart-web test script to ci.yml --- .github/workflows/ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fa0acf2118..ca4b79c45e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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