Buggy code:
@ Override public void updateHaMasterAddress ( String newAddr ) { } @ Override public long now ( ) { } public CommitLog getCommitLog ( ) { } public MessageExt lookMessageByOffset ( long commitLogOffset , int size ) { } public ConsumeQueue findConsumeQueue ( String topic , int queueId ) { } private boolean isTheBatchFull ( int sizePy , int maxMsgNums , int bufferTotal , int messageTotal , boolean isInDisk ) { } private void deleteFile ( final String fileName ) { } private void createTempFile ( ) throws IOException { } private boolean isTempFileExist ( ) { } private boolean loadConsumeQueue ( ) { } public MessageStoreConfig getMessageStoreConfig ( ) { } private void putConsumeQueue ( final String topic , final int queueId , final ConsumeQueue consumeQueue ) { } private void recover ( final boolean lastExitOK ) { } private void recoverTopicQueueTable ( ) { } private void recoverConsumeQueue ( ) { } public void putMessagePostionInfo ( String topic , int queueId , long offset , int size , long tagsCode , long storeTimestamp , long logicOffset ) { } public void putDispatchRequest ( final DispatchRequest dispatchRequest ) { } public DefaultMessageStore . DispatchMessageService getDispatchMessageService ( ) { } public AllocateMappedFileService getAllocateMappedFileService ( ) { } public StoreStatsService getStoreStatsService ( ) { } public RunningFlags getAccessRights ( ) { } public ConcurrentHashMap < String , ConcurrentHashMap < Integer , ConsumeQueue > > getConsumeQueueTable ( ) { } public StoreCheckpoint getStoreCheckpoint ( ) { } public HAService getHaService ( ) { } public ScheduleMessageService getScheduleMessageService ( ) { } public RunningFlags getRunningFlags ( ) { } class CleanCommitLogService { private static final int MaxManualDeleteFileTimes = 20 ; private final double DiskSpaceWarningLevelRatio = Double . parseDouble ( System . getProperty ( "rocketmq.broker.diskSpaceWarningLevelRatio" , "0.90" ) ) ; private final double DiskSpaceCleanForciblyRatio = Double . parseDouble ( System . getProperty ( "rocketmq.broker.diskSpaceCleanForciblyRatio" , "0.85" ) ) ; private long lastRedeleteTimestamp = 0 ; private volatile int manualDeleteFileSeveralTimes = 0 ; private volatile boolean cleanImmediately = false ; public void excuteDeleteFilesManualy ( ) { } public void run ( ) { } public String getServiceName ( ) { } private void redeleteHangedFile ( ) { } private void deleteExpiredFiles ( ) { } private boolean isSpaceToDelete ( ) { } private boolean isTimeToDelete ( ) { } public int getManualDeleteFileSeveralTimes ( ) { } public void setManualDeleteFileSeveralTimes ( int manualDeleteFileSeveralTimes ) { } } class CleanConsumeQueueService { private long lastPhysicalMinOffset = 0 ; private void deleteExpiredFiles ( ) { } public void run ( ) { } public String getServiceName ( ) { } } class FlushConsumeQueueService extends ServiceThread { private static final int RetryTimesOver = 3 ; private long lastFlushTimestamp = 0 ; private void doFlush ( int retryTimes ) { } public void run ( ) { } @ Override public String getServiceName ( ) { } @ Override public long getJoinTime ( ) { } } class DispatchMessageService extends ServiceThread { private volatile List < DispatchRequest > requestsWrite ; private volatile List < DispatchRequest > requestsRead ; public DispatchMessageService ( int putMsgIndexHighWater ) { } public boolean hasRemainMessage ( ) { } public void putRequest ( final DispatchRequest dispatchRequest ) { } private void swapRequests ( ) { } private void doDispatch ( ) { } public void run ( ) { } @ Override protected void onWaitEnd ( ) { } @ Override public String getServiceName ( ) { } } class ReputMessageService extends ServiceThread { private volatile long reputFromOffset = 0 ; public long getReputFromOffset ( ) { } public void setReputFromOffset ( long reputFromOffset ) { } private void doReput ( ) { for ( boolean doNext = true ; doNext ; ) { SelectMappedBufferResult result = DefaultMessageStore . this . commitLog . getData ( reputFromOffset ) ; if ( result != null ) { <START_BUG> if ( 0 == ( reputFromOffset ) ) { <END_BUG> reputFromOffset = result . getStartOffset ( ) ; } try { for ( int readSize = 0 ; ( readSize < ( result . getSize ( ) ) ) && doNext ; ) { DispatchRequest dispatchRequest = DefaultMessageStore . this . commitLog . checkMessageAndReturnSize ( result . getByteBuffer ( ) , false , false ) ; int size = dispatchRequest . getMsgSize ( ) ; if ( size > 0 ) { DefaultMessageStore . this . putDispatchRequest ( dispatchRequest ) ; this . reputFromOffset += size ; readSize += size ; DefaultMessageStore . this . storeStatsService . getSinglePutMessageTopicTimesTotal ( dispatchRequest . getTopic ( ) ) . incrementAndGet ( ) ; DefaultMessageStore . this . storeStatsService . getSinglePutMessageTopicSizeTotal ( dispatchRequest . getTopic ( ) ) . addAndGet ( dispatchRequest . getMsgSize ( ) ) ; } else if ( size == ( - 1 ) ) { doNext = false ; } else if ( size == 0 ) { this . reputFromOffset = DefaultMessageStore . this . commitLog . rollNextFile ( this . reputFromOffset ) ; readSize = result . getSize ( ) ; } } } finally { result . release ( ) ; } } else { doNext = false ; } } } @ Override public void run ( ) { } @ Override public String getServiceName ( ) { } } @ Override public long getCommitLogOffsetInQueue ( String topic , int queueId , long cqOffset ) { } @ Override public long getMinPhyOffset ( ) { } @ Override public long slaveFallBehindMuch ( ) { } @ Override public int cleanUnusedTopic ( Set < String > topics ) { } public Map < String , Long > getMessageIds ( final String topic , final int queueId , long minOffset , long maxOffset , SocketAddress storeHost ) { } private boolean checkInDiskByCommitOffset ( long offsetPy ) { } @ Override public boolean checkInDiskByConsumeOffset ( final String topic , final int queueId , long consumeOffset ) { }

Fix:
if ( ( 0 == ( reputFromOffset ) ) || ( ( reputFromOffset ) < ( result . getStartOffset ( ) ) ) ) {