From 65a8992f10af1c8ad327ca9dee970c4bc44586dc Mon Sep 17 00:00:00 2001 From: tomascz Date: Mon, 19 Feb 2024 09:41:00 +0100 Subject: [PATCH] [#57] Support for KryoFlux and associated images (Part 192: Fixed buffer overrun in track normalization) --- Main/src/Image.h | 2 +- Main/src/Image_TrackRW.cpp | 25 ++++++++++++++----------- Main/src/stdafx.h | 2 +- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Main/src/Image.h b/Main/src/Image.h index a0370f16..b56ac9cf 100644 --- a/Main/src/Image.h +++ b/Main/src/Image.h @@ -412,7 +412,7 @@ void RemoveConsecutiveBeforeEnd(TLogTime tEndMax); }; protected: - const PLogTime logTimes; // absolute logical times since the start of recording + PLogTime logTimes; // absolute logical times since the start of recording const TDecoderMethod method; bool resetDecoderOnIndex; DWORD iNextTime,nLogTimes; diff --git a/Main/src/Image_TrackRW.cpp b/Main/src/Image_TrackRW.cpp index 2ddb7a74..32881529 100644 --- a/Main/src/Image_TrackRW.cpp +++ b/Main/src/Image_TrackRW.cpp @@ -1525,10 +1525,11 @@ // - ignoring what's before the first Index TLogTime tCurrIndexOrg=RewindToIndex(0); // - normalization - const TLogTime tLastIndex=GetIndexTime(nIndexPulses-1); + const TLogTime tLastIndex=GetLastIndexTime(); const DWORD iModifStart=iNextTime; DWORD iTime=iModifStart; - const Utils::CCallocPtr buffer(GetBufferCapacity()); + const DWORD nLogTimesMaxNew=std::max( nIndexPulses*mp->nCells, GetBufferCapacity() ); + const Utils::CCallocPtr buffer( nLogTimesMaxNew, 0 ); // pessimistic estimation for FM encoding const PLogTime ptModified=buffer.get(); for( BYTE nextIndex=1; nextIndex=GetBufferCapacity()) - return ERROR_INSUFFICIENT_BUFFER; // mustn't overrun the Buffer - ::memmove( logTimes+iTime, logTimes+iNextTime, (nLogTimes-iNextTime)*sizeof(TLogTime) ); - nLogTimes+=iTime-iNextTime; - if (const TLogTime dt=indexPulses[nIndexPulses-1]-tLastIndex) - for( DWORD i=iTime; i