tendermint/js-abci

[0.35.2] RangeError: index out of range: 11 + 1 > 11

faustbrian opened this issue · 3 comments

While building my own ABCI I was attempting to look at this official JS ABCI but ran into an issue with the proto files. Initially it was caused by them being outdated because I run 0.35.2 locally. I went ahead and updated them to the files from the v0.35.2 branch of the https://github.com/tendermint?type=source repository but that still didn't yield any better results.

Have any of the message encodings recently changed so that the whole message handling before the protobuf parsing in this ABCI has to be updated?

Changes
https://github.com/faustbrian/js-abci/commit/e59b391efac5c6b72b4884544747f09c4776d65c

Reproduction

git clone git@github.com:faustbrian/js-abci.git
cd js-abci
npm install
node examples/counter.js
tendermint unsafe-reset-all && tendermint init validator && tendermint start

Error

/Users/devjs-abci/node_modules/protobufjs/src/reader.js:13
    return RangeError("index out of range: " + reader.pos + " + " + (writeLength || 1) + " > " + reader.len);
           ^

RangeError: index out of range: 11 + 1 > 11
    at indexOutOfRange (/Users/devjs-abci/node_modules/protobufjs/src/reader.js:13:12)
    at BufferReader.readLongVarint (/Users/devjs-abci/node_modules/protobufjs/src/reader.js:140:23)
    at BufferReader.read_uint64 [as uint64] (/Users/devjs-abci/node_modules/protobufjs/src/reader.js:389:35)
    at Function.decode (/Users/devjs-abci/types.js:1159:55)
    at Function.decode (/Users/devjs-abci/types.js:286:74)
    at Connection.maybeReadNextMessage (/Users/devjs-abci/src/connection.js:55:27)
    at Connection.onData (/Users/devjs-abci/src/connection.js:32:10)
    at Socket.emit (node:events:390:28)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)

Taking a closer look this seems to be caused by faulty data. It attempts to decode 161a140a06302e33352e32100b18082206302e31372e30021200 through the RequestInfo schema but it blows up on the blockVersion property that seems to be missing.

161a140a06302e33352e32100b18082206302e31372e30021200 as UTF-8

���
�0.35.2����"�0.17.0��

Probable Cause

case 2:
	message.blockVersion = reader.uint64(); // blows up here because only the version and abciVersion are present in the received data
	break;

In what case would the blockVersion and p2pVersion properties be missing?

This seems to be caused by the >> 1 part in https://github.com/tendermint/js-abci/blob/master/src/connection.js#L36. Removing this restores the communication between Tendermint and the ABCI server.

@alessio could you or someone else that is familiar with this test this and confirm if removing the >> 1 is in compliance with the length-prefixed serialisation defined in https://docs.tendermint.com/master/spec/abci/client-server.html#tsp?

There's also the need to remove the << 1 at https://github.com/tendermint/js-abci/blob/master/src/connection.js#L87 or requests and responses beyond info won't be processed.