Skip to content

Commit e737e33

Browse files
committed
fixup! Fix potential integer overflow at end of stream
1 parent 202da53 commit e737e33

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

audiostream/src/ni/media/audio/os/win/media_foundation_helper.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ template <class Source>
6565
class SyncronousByteStream : public IMFByteStream
6666
{
6767

68+
static constexpr auto endOfSequence = -1;
69+
6870
auto tell() -> std::streamsize
6971
{
7072
auto pos = m_source.seek( boost::iostreams::stream_offset( 0 ), BOOST_IOS::cur );
@@ -87,7 +89,11 @@ class SyncronousByteStream : public IMFByteStream
8789
try
8890
{
8991
const auto result = m_source.read( reinterpret_cast<char*>( buffer ), toRead );
90-
*read = static_cast<ULONG>( result == -1 ? 0 : result );
92+
if(result < endOfSequence)
93+
{
94+
return E_FAIL;
95+
}
96+
*read = static_cast<ULONG>( result == endOfSequence ? 0 : result );
9197
return S_OK;
9298
}
9399
catch ( const std::system_error& )

0 commit comments

Comments
 (0)