Skip to content

Encoding a message with a null string field throws an error #709

@paralin

Description

@paralin

protobuf.js version:

├─ protobufjs@6.6.5
│  ├─ @protobufjs/aspromise@^1.1.1
│  ├─ @protobufjs/base64@^1.1.1
│  ├─ @protobufjs/codegen@^1.0.8
│  ├─ @protobufjs/eventemitter@^1.1.0
│  ├─ @protobufjs/fetch@^1.1.0
│  ├─ @protobufjs/inquire@^1.1.0
│  ├─ @protobufjs/path@^1.1.2
│  ├─ @protobufjs/pool@^1.1.0
│  ├─ @protobufjs/utf8@^1.1.0
│  ├─ @types/long@^3.0.31
│  ├─ @types/node@7.0.5
│  └─ long@^3.2.0

Encoding a message with string fields filled in with null seems to cause the following error in Node:

TypeError: "string" must be a string, Buffer, or ArrayBuffer
    at Function.byteLength (buffer.js:362:11)
    at BufferWriter.write_string_buffer [as string] (/home/paralin/Documents/goworkspace/src/github.com/fuserobotics/fusecloud-common/node_modules/protobufjs/src/writer_buffer.js:68:22)
    at Type._rgraphql_RGQLQueryTreeNode$encode [as encode] (eval at eof (/home/paralin/Documents/goworkspace/src/github.com/fuserobotics/fusecloud-common/node_modules/@protobufjs/codegen/index.js:103:25), <anonymous>:9:16)
    at Type._rgraphql_RGQLSerialOperation$encode [as encode] (eval at eof (/home/paralin/Documents/goworkspace/src/github.com/fuserobotics/fusecloud-common/node_modules/@protobufjs/codegen/index.js:103:25), <anonymous>:15:12)
    at Type._rgraphql_RGQLClientMessage$encode [as encode] (eval at eof (/home/paralin/Documents/goworkspace/src/github.com/fuserobotics/fusecloud-common/node_modules/@protobufjs/codegen/index.js:103:25), <anonymous>:9:12)
    at Type._socketbus_SBClientMessage$encode [as encode] (eval at eof (/home/paralin/Documents/goworkspace/src/github.com/fuserobotics/fusecloud-common/node_modules/@protobufjs/codegen/index.js:103:25), <anonymous>:9:12)
    at repl:1:24
    at realRunInThisContextScript (vm.js:22:35)
    at sigintHandlersWrap (vm.js:98:12)
    at ContextifyScript.Script.runInThisContext (vm.js:24:12)

And the following in the browser:

TypeError: Cannot read property 'length' of null
    at Object.utf8_length [as length] (index.js:18)
    at Writer.write_string [as string] (writer.js:491)
    at Type._rgraphql_RGQLQueryTreeNode$encode [as encode] (eval at eof (index.js:103), <anonymous>:9:16)
    at Type.encode_setup [as encode] (type.js:406)
    at Type._rgraphql_RGQLSerialOperation$encode [as encode] (eval at eof (index.js:103), <anonymous>:15:12)
    at Type.encode_setup [as encode] (type.js:406)
    at Type._rgraphql_RGQLClientMessage$encode [as encode] (eval at eof (index.js:103), <anonymous>:9:12)
    at Type.encode_setup [as encode] (type.js:406)
    at Type._socketbus_SBClientMessage$encode [as encode] (eval at eof (index.js:103), <anonymous>:9:12)

Null strings should be treated as empty value, IMO. I haven't had a chance to make an isolated repro yet. Will post one tomorrow if you haven't already fixed this.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions