[vlc-devel] [PATCH 4/4] demux/nsv: do not read chunks greater than SSIZE_MAX
Filip Roséen
filip at atch.se
Mon Oct 31 01:05:56 CET 2016
On a 32-bit platform, SSIZE_MAX is generally smaller than UINT32_MAX,
meaning that invoking vlc_stream_Read where the size argument is
UINT32_MAX makes it impossible for vlc_stream_Read to signal that the
reading was successful.
These changes reads data in chunks of at most SSIZE_MAX to prevent the
previously described issue.
---
modules/demux/nsv.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/modules/demux/nsv.c b/modules/demux/nsv.c
index 61e56c0..2421664 100644
--- a/modules/demux/nsv.c
+++ b/modules/demux/nsv.c
@@ -32,6 +32,7 @@
#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_demux.h>
+#include <limits.h>
/* TODO:
* - implement NSVf parsing (to get meta data)
@@ -459,8 +460,18 @@ static int ReadNSVf( demux_t *p_demux )
if( i_header_size == 0 || i_header_size == UINT32_MAX )
return VLC_EGENERIC;
+ for( ssize_t i_req; i_header_size; i_header_size -= i_req )
+ {
+#if SSIZE_MAX < UINT32_MAX
+ i_req = __MIN( SSIZE_MAX, i_header_size );
+#else
+ i_req = i_header_size;
+#endif
+ if( vlc_stream_Read( p_demux->s, NULL, i_req ) != i_req )
+ return VLC_EGENERIC;
+ }
- return vlc_stream_Read( p_demux->s, NULL, i_size ) == i_size ? VLC_SUCCESS : VLC_EGENERIC;
+ return VLC_SUCCESS;
}
/*****************************************************************************
* ReadNSVs:
--
2.10.1
More information about the vlc-devel
mailing list