Skip to content

decoder: zero-field messages reject well-formed unknown groups #1

Description

@JavaGT

Audit finding (sweep1-runtime, /Users/server/Development/external-tools/reports/protobufjs/sweep1-runtime.md). Wire-correctness bug.

Evidence: src/decoder.js:286 generates r.skipType(t&7,q,t) when the message type has zero fields. The t>>>=3 reassignment (decoder.js:69) only happens inside if (mtype.fieldsArray.length), so the third argument (fieldNumber) is the full tag, not the field number. Reader.skipType (src/reader.js:822) compares the nested end tag's field number against it and always mismatches → throws.

Repro (verified):

const pb = require('./src/index.js');
const root = pb.Root.fromJSON({ nested: { T: { fields: {} }, U: { fields: { x: { type:'int32', id:1 } } } } });
const bytes = Uint8Array.from([0x0b, 0x0c]); // group f1 + matching end tag
root.lookupType('T').decode(bytes); // throws "invalid end group tag"
root.lookupType('U').decode(bytes); // OK

Decision question: Adopt the one-line fix (t>>>3 when no fields) plus a regression test with the two-byte repro?

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions