Buggy code:
public class BlockInStream extends InStream { private static final Logger LOG = LoggerFactory . getLogger ( LOGGER_TYPE ) ; private static final int BUFFER_SIZE = ( ( int ) ( PageUtils . ceilingPageMultiple ( UserConf . get ( ) . REMOTE_READ_BUFFER_SIZE_BYTE ) ) ) ; private final int mBlockIndex ; private ClientBlockInfo mBlockInfo ; private int mBlockLockId ; private static class WorkerInfoPair implements Comparable < BlockInStream . WorkerInfoPair > { public WorkerInfoPair ( NetAddress mAddress , long mStorageDirId ) { } private NetAddress mAddress ; private long mStorageDirId ; public NetAddress getAddress ( ) { } public void setAddress ( NetAddress address ) { } public long getStorageDirId ( ) { } public void setStorageDirId ( long storageDirId ) { } @ Override public int compareTo ( BlockInStream . WorkerInfoPair o ) { } } List < BlockInStream . WorkerInfoPair > mSortedWorkers ; private long mBlockPos = 0 ; private final BlockReader mLocalBlockReader ; private ByteBuffer mBuffer ; private int mBufferStartPage = - 1 ; private FileChannel mLocalPageChannel = null ; private int mLocalPageChannelStartPage = - 1 ; private static final long MINIMUM_FILE_CHANNEL_READ_SIZE = 32 * ( Constants . KB ) ; private long mNumBytesRead = 0 ; private long mNumReads = 0 ; private InputStream mCheckpointInputStream ; private long mCheckpointPos = - 1 ; private final Object mUFSConf ; private boolean mRecache ; private final ClientBlockCacher mBlockCacher ; private boolean mClosed = false ; BlockInStream ( TachyonFile file , ReadType readType , int blockIndex ) throws IOException { } BlockInStream ( TachyonFile file , ReadType readType , int blockIndex , Object ufsConf ) throws IOException { } private static List < BlockInStream . WorkerInfoPair > buildSortedWorkers ( ClientBlockInfo blockInfo ) { } @ Override public void close ( ) throws IOException { } @ Override public int read ( ) throws IOException { } @ Override public int read ( byte [ ] b ) throws IOException { } @ Override public int read ( byte [ ] b , int off , int len ) throws IOException { } private int readLocal ( byte [ ] b , int off , int len ) throws IOException { } private int readRemote ( byte [ ] b , int off , int len ) throws IOException { } public static ByteBuffer readRemoteByteBuffer ( TachyonFS tachyonFS , ClientBlockInfo blockInfo , long offset , long len ) { } private static ByteBuffer readRemoteByteBuffer ( TachyonFS tachyonFS , ClientBlockInfo blockInfo , List < BlockInStream . WorkerInfoPair > sortedWorkers , long offset , long len ) { } private static ByteBuffer retrieveByteBufferFromRemoteMachine ( InetSocketAddress address , long blockId , long offset , long length ) throws IOException { } private int readRestFromUnderFS ( byte [ ] b , int off , int len ) throws IOException { long requiredStreamPosition = ( mRecache ) ? PageUtils . getPageOffset ( PageUtils . getPageId ( mBlockPos ) ) : mBlockPos ; if ( ( ( mCheckpointPos ) == ( - 1 ) ) || ( ( mCheckpointPos ) > requiredStreamPosition ) ) { if ( ( mCheckpointPos ) != ( - 1 ) ) { mCheckpointInputStream . close ( ) ; } String checkpointPath = mFile . getUfsPath ( ) ; BlockInStream . LOG . debug ( ( "Opening<seq2seq4repair_space>stream<seq2seq4repair_space>from<seq2seq4repair_space>underlayer<seq2seq4repair_space>fs:<seq2seq4repair_space>" + checkpointPath ) ) ; if ( checkpointPath . equals ( "" ) ) { return 0 ; } UnderFileSystem underfsClient = UnderFileSystem . get ( checkpointPath , mUFSConf ) ; mCheckpointInputStream = underfsClient . open ( checkpointPath ) ; if ( ( mCheckpointInputStream . skip ( mBlockInfo . getOffset ( ) ) ) != ( mBlockInfo . getOffset ( ) ) ) { throw new IOException ( ( ( "Failed<seq2seq4repair_space>to<seq2seq4repair_space>skip<seq2seq4repair_space>to<seq2seq4repair_space>the<seq2seq4repair_space>block<seq2seq4repair_space>offset<seq2seq4repair_space>" + ( mBlockInfo . getOffset ( ) ) ) + "<seq2seq4repair_space>in<seq2seq4repair_space>the<seq2seq4repair_space>checkpoint<seq2seq4repair_space>file" ) ) ; } mCheckpointPos = 0 ; } final long skipAmount = requiredStreamPosition - ( mCheckpointPos ) ; if ( ( mCheckpointInputStream . skip ( skipAmount ) ) != skipAmount ) { throw new IOException ( ( ( "Failed<seq2seq4repair_space>to<seq2seq4repair_space>skip<seq2seq4repair_space>to<seq2seq4repair_space>the<seq2seq4repair_space>block<seq2seq4repair_space>offset<seq2seq4repair_space>" + requiredStreamPosition ) + "<seq2seq4repair_space>(relative<seq2seq4repair_space>to<seq2seq4repair_space>the<seq2seq4repair_space>block)<seq2seq4repair_space>in<seq2seq4repair_space>the<seq2seq4repair_space>checkpoint<seq2seq4repair_space>file" ) ) ; } mCheckpointPos = requiredStreamPosition ; if ( mRecache ) { assert ( ( mBufferStartPage ) == ( - 1 ) ) || ( ! ( mBuffer . hasRemaining ( ) ) ) ; int lenToRead = ( ( int ) ( ( Math . min ( mBlockInfo . getLength ( ) , PageUtils . ceilingPageMultiple ( ( ( mBlockPos ) + len ) ) ) ) - ( mCheckpointPos ) ) ) ; mBuffer = ByteBuffer . allocate ( lenToRead ) ; mBufferStartPage = PageUtils . getPageId ( mCheckpointPos ) ; int bytesRead = 0 ; while ( bytesRead < lenToRead ) { int justRead = mCheckpointInputStream . read ( mBuffer . array ( ) , bytesRead , ( lenToRead - bytesRead ) ) ; if ( justRead <= 0 ) { return bytesRead ; } bytesRead += justRead ; } mBlockCacher . writePages ( mBlockInfo , PageUtils . getPageId ( mCheckpointPos ) , mBuffer ) ; mBuffer . position ( ( ( int ) ( ( mBlockPos ) - ( mCheckpointPos ) ) ) ) ; mBuffer . get ( b , off , len ) ; mCheckpointPos += lenToRead ; } else { int bytesRead = 0 ; while ( bytesRead < len ) { <START_BUG> int justRead = mCheckpointInputStream . read ( b , ( off + bytesRead ) , len ) ; <END_BUG> if ( justRead <= 0 ) { return bytesRead ; } bytesRead += justRead ; } mCheckpointPos += len ; } return len ; } @ Override public void seek ( long pos ) throws IOException { } @ Override public long skip ( long n ) throws IOException { } }

Fix:
int justRead = mCheckpointInputStream . read ( b , ( off + bytesRead ) , ( len - bytesRead ) ) ;