core/thrift7/src/main/java/com/twitter/elephantbird/thrift/AbstractThriftBinaryProtocol.java
protected void checkContainerSize(int size) throws TProtocolException {
    if (size < 0) {
      throw new TProtocolException("Negative container size: " + size);
    }

    if (checkReadLength_ && (readLength_ - size) < 0) {
      throw new TProtocolException("Remaining message length is " + readLength_
              + " but container size in underlying TTransport is set to at least: " + size);
    }
  }
protected void checkContainerSize(int size) throws TProtocolException {
    if (size < 0) {
      throw new TProtocolException("Negative container size: " + size);
    }

    if (checkReadLength_ && (readLength_ - size) < 0) {
      throw new TProtocolException("Remaining message length is " + readLength_
              + " but container size in underlying TTransport is set to at least: " + size);
    }
  }
Check if the container size is valid.

NOTE: This assumes that the elements are one byte each. So this does not
catch all cases, but does increase the chances of handling malformed
lengths when the number of remaining bytes in the underlying Transport is
clearly less than the container size that the Transport provides.