Skip to content

[protobuf] _decode32Bits() bug in ProtobufParser #85

Closed
@marsqing

Description

@marsqing
protected final int _decode32Bits() throws IOException {
    int ptr = this._inputPtr;
    if(ptr + 3 >= this._inputEnd) {
      return this._slow32();
    } else {
      byte[] b = this._inputBuffer;
      int v = (b[ptr] & 255) + (b[ptr + 1] << 8) + ((b[ptr + 2] & 255) << 16) + (b[ptr + 3] << 24);
      this._inputPtr = ptr + 4;
      return v;
    }
  }

bug in the following line
int v = (b[ptr] & 255) + (b[ptr + 1] << 8) + ((b[ptr + 2] & 255) << 16) + (b[ptr + 3] << 24);

If b[prt+1] or b[ptr+3] is negative, << will preserve sign and the overall plus operation will corrupt. Float values like 123.456f will be incorrectly decoded.

_decode64Bits()'s logic is correct.

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