-
Notifications
You must be signed in to change notification settings - Fork 197
Open
Labels
Description
We attempt to check the ranges of added int elements to lists:
protobuf.dart/protobuf/lib/src/protobuf/field_info.dart
Lines 96 to 99 in 9b4c46f
| /// Function to verify items when adding to a repeated field. | |
| /// | |
| /// Only available in repeated fields. | |
| final CheckFunc<T>? check; |
protobuf.dart/protobuf/lib/src/protobuf/field_error.dart
Lines 97 to 100 in 9b4c46f
| case PbFieldType.INT32_BIT: | |
| case PbFieldType.SINT32_BIT: | |
| case PbFieldType.SFIXED32_BIT: | |
| return _checkSigned32; |
| final CheckFunc<E> _check; |
But it doesn't seem to work currently. Repro:
edition = "2024";
message Foo {
repeated int32 int_list = 1;
}import 'test.pb.dart';
void main() {
Foo foo = Foo();
foo.intList.add(1 << 40);
print(foo);
print(Foo.fromBuffer(foo.writeToBuffer()));
}This works, but the roundtripping does not generate the original message as we've added a number too large for the wire format of int32.
There are also other issues that are somewhat related, but I'll probably track in separate issues:
PbMapdoesn't have acheckFuncso it also allows adding numbers outside of the supported range.PbListcan be created directly (withPbList()) which won't have the right check function.
I'm not sure why would you create aPbListdirectly (can it be removed?), but if you do that, you won't be checking the element ranges.