Skip to content
Merged
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
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 @@ -421,7 +421,7 @@ final class Buffer {
/// Reads an unsigned 64-bit integer written by [writeTaggedUint64].
int readTaggedUint64() {
final readIndex = _readerIndex;
final first = _view.getInt32(readIndex, Endian.little);
final first = _view.getUint32(readIndex, Endian.little);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes Buffer.readTaggedUint64(), but GeneratedReadCursor.readTaggedUint64() in dart/packages/fory/lib/src/codegen/generated_support.dart still reads the first word with getInt32. Generated serializers route tagged uint64 fields through that cursor path, so 0x7fffffff still round-trips there as 9223372036854775807 instead of 2147483647. The generated path needs the same getUint32 change and a regression test.

if ((first & 1) == 0) {
_readerIndex = readIndex + 4;
return first >>> 1;
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 @@ -364,7 +364,7 @@ final class GeneratedReadCursor {

int readTaggedUint64() {
final readIndex = _offset;
final first = _view.getInt32(readIndex, Endian.little);
final first = _view.getUint32(readIndex, Endian.little);
if ((first & 1) == 0) {
_offset = readIndex + 4;
return first >>> 1;
Expand Down
26 changes: 26 additions & 0 deletions dart/packages/fory/test/buffer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import 'package:fory/fory.dart';
import 'package:fory/src/codegen/generated_support.dart';
import 'package:test/test.dart';

void main() {
Expand Down Expand Up @@ -46,5 +47,30 @@ void main() {
expect(buffer.readVarInt64(), equals(-17));
expect(buffer.readVarUint64(), equals(9000));
});

test('tagged uint64 sign extension regression', () {
final buffer = Buffer();
final testValue = 0x7FFFFFFF;

buffer.writeTaggedUint64(testValue);
buffer.wrap(buffer.toBytes());

final result = buffer.readTaggedUint64();

expect(result, equals(testValue));
});

test('GeneratedReadCursor tagged uint64 sign extension regression', () {
final buffer = Buffer();
final testValue = 0x7FFFFFFF;

buffer.writeTaggedUint64(testValue);
buffer.wrap(buffer.toBytes());

final cursor = GeneratedReadCursor.start(buffer);
final result = cursor.readTaggedUint64();

expect(result, equals(testValue));
});
});
}
Loading