Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
paralin opened this issue Mar 18, 2017 · 2 comments
Closed

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

paralin opened this issue Mar 18, 2017 · 2 comments

Comments

@paralin
Copy link

paralin commented Mar 18, 2017

protobuf.js version:

├─ [email protected]
│  ├─ @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/[email protected]
│  └─ 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.

@dcodeIO
Copy link
Member

dcodeIO commented Mar 18, 2017

This is true for primitive types, like string, number and boolean.

Relevant line is here: https://github.com/dcodeIO/protobuf.js/blob/master/src/encoder.js#L115

@dcodeIO
Copy link
Member

dcodeIO commented Mar 22, 2017

Should be working in master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants