Skip to content

Possible to create PbLists without value validity checks, PbMap does not validate elements  #1065

@osa1

Description

@osa1

We attempt to check the ranges of added int elements to lists:

/// Function to verify items when adding to a repeated field.
///
/// Only available in repeated fields.
final CheckFunc<T>? check;

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:

  • PbMap doesn't have a checkFunc so it also allows adding numbers outside of the supported range.
  • PbList can be created directly (with PbList()) which won't have the right check function.
    I'm not sure why would you create a PbList directly (can it be removed?), but if you do that, you won't be checking the element ranges.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions