@VisibleForTesting
  static BufferChunk readLengthBytesFromSmallBuffers(BufferChunk first, long cbStartOffset,
      int[] result, List<IncompleteCb> badEstimates, boolean isTracingEnabled, IoTrace trace)
          throws IOException {
    if (!first.hasContiguousNext()) {
      badEstimates.add(addIncompleteCompressionBuffer(
          cbStartOffset, first, 0, isTracingEnabled, trace));
      return null; // This is impossible to read from this chunk.
    }
    int ix = readLengthBytes(first.getData(), result, 0);
    assert ix < 3; // Otherwise we wouldn't be here.
    DiskRangeList current = first.next;
    first.removeSelf();
    while (true) {
      if (!(current instanceof BufferChunk)) {
        throw new IOException(
            "Trying to extend compressed block into uncompressed block " + current);
      }
      BufferChunk currentBc = (BufferChunk) current;
      ix = readLengthBytes(currentBc.getData(), result, ix);
      if (ix == 3) return currentBc; // Done, we have 3 bytes. Continue reading this buffer.
      DiskRangeList tmp = current;
      current = current.hasContiguousNext() ? current.next : null;
      if (current != null) {
        if (isTracingEnabled) {
          LOG.trace("Removing partial CB " + tmp + " from ranges after copying its contents");
        }
        trace.logPartialCb(tmp);
        tmp.removeSelf();
      } else {
        badEstimates.add(addIncompleteCompressionBuffer(
            cbStartOffset, tmp, -1, isTracingEnabled, trace));
        return null; // This is impossible to read from this chunk.
      }
    }
  }
Reads one compression block from the source; handles compression blocks read from
multiple ranges (usually, that would only happen with zcr).
Adds stuff to cachedBuffers, toDecompress and toRelease (see below what each does).
@param current BufferChunk where compression block starts.
@param cacheBuffers The result buffer array to add pre-allocated target cache buffer.
@param toDecompress The list of work to decompress - pairs of compressed buffers and the
                    target buffers (same as the ones added to cacheBuffers).
@param toRelease The list of buffers to release to zcr because they are no longer in use.
@param badEstimates The list of bad estimates that cannot be decompressed.
@return The resulting cache chunk.
ql/src/java/org/apache/hadoop/hive/ql/io/orc/encoded/EncodedReaderImpl.java