Skip to content

Commit

Permalink
Fix implicit signed to unsigned conversion in CMultiVolumeInStream
Browse files Browse the repository at this point in the history
  • Loading branch information
rikyoz committed Oct 15, 2023
1 parent b780df6 commit 8768fd9
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/internal/cmultivolumeinstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,23 @@ STDMETHODIMP CMultiVolumeInStream::Seek( Int64 offset, UInt32 seekOrigin, UInt64
return STG_E_INVALIDFUNCTION;
}

// Checking if adding the (negative) offset would result in the unsigned wrap around of the current position.
if ( offset < 0 && originPosition < static_cast< uint64_t >( -offset ) ) {
return HRESULT_WIN32_ERROR_NEGATIVE_SEEK;
}

// Checking if adding the (positive) offset would result in the unsigned wrap around of the current position.
if ( offset > 0 ) {
// Checking if adding the offset would result in the unsigned wrap around of the current position.
if ( offset < 0 ) {
const auto positiveOffset = static_cast< uint64_t >( -offset );
if ( originPosition < positiveOffset ) {
return HRESULT_WIN32_ERROR_NEGATIVE_SEEK;
}
mCurrentPosition = originPosition - positiveOffset;
} else if ( offset == 0 ) {
mCurrentPosition = originPosition;
} else {
const auto positiveOffset = static_cast< uint64_t >( offset );
const uint64_t seekPosition = originPosition + positiveOffset;
if ( seekPosition < originPosition || seekPosition < positiveOffset ) {
return E_INVALIDARG;
}
mCurrentPosition = seekPosition;
}
mCurrentPosition = originPosition + offset;

if ( newPosition != nullptr ) {
*newPosition = mCurrentPosition;
Expand Down

0 comments on commit 8768fd9

Please sign in to comment.