Buggy code:
public class CommitLog { private static final int MAX_OUTSTANDING_REPLAY_COUNT = 1024 ; static final Logger logger = LoggerFactory . getLogger ( CommitLog . class ) ; public static final CommitLog instance = new CommitLog ( ) ; private final Deque < CommitLogSegment > segments = new ArrayDeque < CommitLogSegment > ( ) ; private final ICommitLogExecutorService executor ; private volatile int segmentSize = ( 128 * 1024 ) * 1024 ; private CommitLog ( ) { } public void resetUnsafe ( ) { } private boolean manages ( String name ) { } public static void recover ( ) throws IOException { } public static void recover ( File [ ] clogs ) throws IOException { Set < Table > tablesRecovered = new HashSet < Table > ( ) ; List < Future < ? > > futures = new ArrayList < Future < ? > > ( ) ; byte [ ] bytes = new byte [ 4096 ] ; Map < Integer , AtomicInteger > invalidMutations = new HashMap < Integer , AtomicInteger > ( ) ; for ( File file : clogs ) { <START_BUG> int bufferSize = ( ( int ) ( Math . min ( file . length ( ) , ( ( 32 * 1024 ) * 1024 ) ) ) ) ; <END_BUG> BufferedRandomAccessFile reader = new BufferedRandomAccessFile ( new File ( file . getAbsolutePath ( ) ) , "r" , bufferSize , true ) ; try { CommitLogHeader clHeader = null ; int replayPosition = 0 ; String headerPath = CommitLogHeader . getHeaderPathFromSegmentPath ( file . getAbsolutePath ( ) ) ; try { clHeader = CommitLogHeader . readCommitLogHeader ( headerPath ) ; replayPosition = clHeader . getReplayPosition ( ) ; } catch ( IOException ioe ) { CommitLog . logger . info ( ( headerPath + "<seq2seq4repair_space>incomplete,<seq2seq4repair_space>missing<seq2seq4repair_space>or<seq2seq4repair_space>corrupt.<seq2seq4repair_space>Everything<seq2seq4repair_space>is<seq2seq4repair_space>ok,<seq2seq4repair_space>don't<seq2seq4repair_space>panic.<seq2seq4repair_space>CommitLog<seq2seq4repair_space>will<seq2seq4repair_space>be<seq2seq4repair_space>replayed<seq2seq4repair_space>from<seq2seq4repair_space>the<seq2seq4repair_space>beginning" ) ) ; CommitLog . logger . debug ( "exception<seq2seq4repair_space>was" , ioe ) ; } if ( replayPosition < 0 ) { CommitLog . logger . debug ( "skipping<seq2seq4repair_space>replay<seq2seq4repair_space>of<seq2seq4repair_space>fully-flushed<seq2seq4repair_space>{}" , file ) ; continue ; } reader . seek ( replayPosition ) ; if ( CommitLog . logger . isDebugEnabled ( ) ) CommitLog . logger . debug ( ( ( ( "Replaying<seq2seq4repair_space>" + file ) + "<seq2seq4repair_space>starting<seq2seq4repair_space>at<seq2seq4repair_space>" ) + ( reader . getFilePointer ( ) ) ) ) ; while ( ! ( reader . isEOF ( ) ) ) { if ( CommitLog . logger . isDebugEnabled ( ) ) CommitLog . logger . debug ( ( "Reading<seq2seq4repair_space>mutation<seq2seq4repair_space>at<seq2seq4repair_space>" + ( reader . getFilePointer ( ) ) ) ) ; long claimedCRC32 ; Checksum checksum = new CRC32 ( ) ; int serializedSize ; try { serializedSize = reader . readInt ( ) ; if ( serializedSize < 10 ) break ; long claimedSizeChecksum = reader . readLong ( ) ; checksum . update ( serializedSize ) ; if ( ( checksum . getValue ( ) ) != claimedSizeChecksum ) break ; if ( serializedSize > ( bytes . length ) ) bytes = new byte [ ( ( int ) ( 1.2 * serializedSize ) ) ] ; reader . readFully ( bytes , 0 , serializedSize ) ; claimedCRC32 = reader . readLong ( ) ; } catch ( EOFException eof ) { break ; } checksum . update ( bytes , 0 , serializedSize ) ; if ( claimedCRC32 != ( checksum . getValue ( ) ) ) { continue ; } ByteArrayInputStream bufIn = new ByteArrayInputStream ( bytes , 0 , serializedSize ) ; RowMutation rm = null ; try { rm = RowMutation . serializer ( ) . deserialize ( new DataInputStream ( bufIn ) ) ; } catch ( UnserializableColumnFamilyException ex ) { AtomicInteger i = invalidMutations . get ( ex . cfId ) ; if ( i == null ) { i = new AtomicInteger ( 1 ) ; invalidMutations . put ( ex . cfId , i ) ; } else i . incrementAndGet ( ) ; continue ; } if ( CommitLog . logger . isDebugEnabled ( ) ) CommitLog . logger . debug ( String . format ( "replaying<seq2seq4repair_space>mutation<seq2seq4repair_space>for<seq2seq4repair_space>%s.%s:<seq2seq4repair_space>%s" , rm . getTable ( ) , ByteBufferUtil . bytesToHex ( rm . key ( ) ) , ( ( "{" + ( StringUtils . join ( rm . getColumnFamilies ( ) , ",<seq2seq4repair_space>" ) ) ) + "}" ) ) ) ; final Table table = Table . open ( rm . getTable ( ) ) ; tablesRecovered . add ( table ) ; final Collection < ColumnFamily > columnFamilies = new ArrayList < ColumnFamily > ( rm . getColumnFamilies ( ) ) ; final long entryLocation = reader . getFilePointer ( ) ; final CommitLogHeader finalHeader = clHeader ; final RowMutation frm = rm ; Runnable runnable = new WrappedRunnable ( ) { public void runMayThrow ( ) throws IOException { RowMutation newRm = new RowMutation ( frm . getTable ( ) , frm . key ( ) ) ; for ( ColumnFamily columnFamily : columnFamilies ) { if ( ( CFMetaData . getCF ( columnFamily . id ( ) ) ) == null ) continue ; if ( ( finalHeader == null ) || ( ( finalHeader . isDirty ( columnFamily . id ( ) ) ) && ( entryLocation > ( finalHeader . getPosition ( columnFamily . id ( ) ) ) ) ) ) newRm . add ( columnFamily ) ; } if ( ! ( newRm . isEmpty ( ) ) ) { Table . open ( newRm . getTable ( ) ) . apply ( newRm , null , false ) ; } } } ; futures . add ( StageManager . getStage ( MUTATION ) . submit ( runnable ) ) ; if ( ( futures . size ( ) ) > ( CommitLog . MAX_OUTSTANDING_REPLAY_COUNT ) ) { FBUtilities . waitOnFutures ( futures ) ; futures . clear ( ) ; } } } finally { FileUtils . closeQuietly ( reader ) ;

Fix:
int bufferSize = ( ( int ) ( Math . min ( Math . max ( file . length ( ) , 1 ) , ( ( 32 * 1024 ) * 1024 ) ) ) ) ;