Commit a463d9bd authored by Laurent Aimar's avatar Laurent Aimar

Made stream_t size and position unsigned.

 It fixes segfaults in src/input/stream.c (at least) when demuxers
overflow int64_t seek position, and avoid testing for negative values
everywhere.
 stream_Tell() and stream_Size() still returns signed values as too much code
depend on it.
parent 2e847d84
......@@ -90,10 +90,10 @@ enum stream_query_e
STREAM_CAN_FASTSEEK, /**< arg1= bool * res=cannot fail*/
/* */
STREAM_SET_POSITION, /**< arg1= int64_t res=can fail */
STREAM_GET_POSITION, /**< arg1= int64_t * res=cannot fail*/
STREAM_SET_POSITION, /**< arg1= uint64_t res=can fail */
STREAM_GET_POSITION, /**< arg1= uint64_t * res=cannot fail*/
STREAM_GET_SIZE, /**< arg1= int64_t * res=cannot fail (0 if no sense)*/
STREAM_GET_SIZE, /**< arg1= uint64_t * res=cannot fail (0 if no sense)*/
/* Special for direct access control from demuxer.
* XXX: avoid using it by all means */
......@@ -124,8 +124,10 @@ VLC_EXPORT( char *, stream_ReadLine, ( stream_t * ) );
*/
static inline int64_t stream_Tell( stream_t *s )
{
int64_t i_pos;
uint64_t i_pos;
stream_Control( s, STREAM_GET_POSITION, &i_pos );
if( i_pos >> 62 )
return (int64_t)1 << 62;
return i_pos;
}
......@@ -134,12 +136,14 @@ static inline int64_t stream_Tell( stream_t *s )
*/
static inline int64_t stream_Size( stream_t *s )
{
int64_t i_pos;
uint64_t i_pos;
stream_Control( s, STREAM_GET_SIZE, &i_pos );
if( i_pos >> 62 )
return (int64_t)1 << 62;
return i_pos;
}
static inline int stream_Seek( stream_t *s, int64_t i_pos )
static inline int stream_Seek( stream_t *s, uint64_t i_pos )
{
return stream_Control( s, STREAM_SET_POSITION, i_pos );
}
......@@ -172,7 +176,7 @@ VLC_EXPORT( void, stream_DemuxSend, ( stream_t *s, block_t *p_block ) );
* You must delete it using stream_Delete.
*/
#define stream_MemoryNew( a, b, c, d ) __stream_MemoryNew( VLC_OBJECT(a), b, c, d )
VLC_EXPORT( stream_t *,__stream_MemoryNew, (vlc_object_t *p_obj, uint8_t *p_buffer, int64_t i_size, bool b_preserve_memory ) );
VLC_EXPORT( stream_t *,__stream_MemoryNew, (vlc_object_t *p_obj, uint8_t *p_buffer, uint64_t i_size, bool b_preserve_memory ) );
/**
* Create a stream_t reading from an URL.
......
......@@ -305,7 +305,7 @@ static int Control( stream_t *s, int i_query, va_list args )
{
case STREAM_SET_POSITION:
{
int64_t i_position = (int64_t)va_arg( args, int64_t );
uint64_t i_position = va_arg( args, uint64_t );
if( i_position >= p_sys->i_len )
return VLC_EGENERIC;
else
......@@ -317,15 +317,15 @@ static int Control( stream_t *s, int i_query, va_list args )
case STREAM_GET_POSITION:
{
int64_t *pi_position = (int64_t*)va_arg( args, int64_t* );
uint64_t *pi_position = va_arg( args, uint64_t* );
*pi_position = p_sys->i_pos;
return VLC_SUCCESS;
}
case STREAM_GET_SIZE:
{
int64_t *pi_size = (int64_t*)va_arg( args, int64_t* );
*pi_size = (int64_t) p_sys->i_len;
uint64_t *pi_size = va_arg( args, uint64_t* );
*pi_size = p_sys->i_len;
return VLC_SUCCESS;
}
......
......@@ -243,10 +243,10 @@ static int Control (stream_t *stream, int query, va_list args)
*(va_arg (args, bool *)) = false;
break;
case STREAM_GET_POSITION:
*(va_arg (args, int64_t *)) = p_sys->offset;
*(va_arg (args, uint64_t *)) = p_sys->offset;
break;
case STREAM_GET_SIZE:
*(va_arg (args, int64_t *)) = 0;
*(va_arg (args, uint64_t *)) = 0;
break;
default:
return VLC_EGENERIC;
......
......@@ -59,19 +59,19 @@ static const int i_rar_marker = sizeof(p_rar_marker);
typedef struct
{
int64_t i_offset;
int64_t i_size;
int64_t i_cummulated_size;
uint64_t i_offset;
uint64_t i_size;
uint64_t i_cummulated_size;
} rar_file_chunk_t;
typedef struct
{
char *psz_name;
int64_t i_size;
uint64_t i_size;
bool b_complete;
int i_chunk;
rar_file_chunk_t **pp_chunk;
int64_t i_real_size; /* Gathered size */
uint64_t i_real_size; /* Gathered size */
} rar_file_t;
static void RarFileDelete( rar_file_t * );
......@@ -81,7 +81,7 @@ struct stream_sys_t
rar_file_t *p_file;
const rar_file_chunk_t *p_chunk;
int64_t i_position;
uint64_t i_position;
uint8_t *p_peek_alloc;
uint8_t *p_peek;
......@@ -97,7 +97,7 @@ static int Peek ( stream_t *, const uint8_t **pp_peek, unsigned int i_peek );
static int Control( stream_t *, int i_query, va_list );
static int Parse ( stream_t * );
static int Seek ( stream_t *s, int64_t i_position );
static int Seek ( stream_t *s, uint64_t i_position );
/****************************************************************************
* Open
......@@ -192,7 +192,7 @@ static int Read( stream_t *s, void *p_read, unsigned int i_read )
while( i_total < i_read )
{
const int64_t i_chunk_end = p_sys->p_chunk->i_cummulated_size + p_sys->p_chunk->i_size;
const uint64_t i_chunk_end = p_sys->p_chunk->i_cummulated_size + p_sys->p_chunk->i_size;
int i_max = __MIN( i_read - i_total, i_chunk_end - p_sys->i_position );
if( i_max <= 0 )
......@@ -257,20 +257,20 @@ static int Control( stream_t *s, int i_query, va_list args )
/* */
case STREAM_SET_POSITION:
{
int64_t i_position = (int64_t)va_arg( args, int64_t );
uint64_t i_position = va_arg( args, uint64_t );
return Seek( s, i_position );
}
case STREAM_GET_POSITION:
{
int64_t *pi_position = (int64_t*)va_arg( args, int64_t* );
uint64_t *pi_position = va_arg( args, uint64_t* );
*pi_position = p_sys->i_position - p_sys->i_peek;
return VLC_SUCCESS;
}
case STREAM_GET_SIZE:
{
int64_t *pi_size = (int64_t*)va_arg( args, int64_t* );
uint64_t *pi_size = (uint64_t*)va_arg( args, uint64_t* );
*pi_size = p_sys->p_file->i_real_size;
return VLC_SUCCESS;
}
......@@ -293,13 +293,11 @@ static int Control( stream_t *s, int i_query, va_list args )
/****************************************************************************
* Helpers
****************************************************************************/
static int Seek( stream_t *s, int64_t i_position )
static int Seek( stream_t *s, uint64_t i_position )
{
stream_sys_t *p_sys = s->p_sys;
if( i_position < 0 )
i_position = 0;
else if( i_position > p_sys->p_file->i_real_size )
if( i_position > p_sys->p_file->i_real_size )
i_position = p_sys->p_file->i_real_size;
/* Search the chunk */
......@@ -313,8 +311,8 @@ static int Seek( stream_t *s, int64_t i_position )
p_sys->i_position = i_position;
p_sys->i_peek = 0;
const int64_t i_seek = p_sys->p_chunk->i_offset +
( i_position - p_sys->p_chunk->i_cummulated_size );
const uint64_t i_seek = p_sys->p_chunk->i_offset +
( i_position - p_sys->p_chunk->i_cummulated_size );
return stream_Seek( s->p_source, i_seek );
}
......@@ -380,9 +378,8 @@ static int PeekBlock( stream_t *s, rar_block_t *p_hdr )
}
static int SkipBlock( stream_t *s, const rar_block_t *p_hdr )
{
int64_t i_size = (int64_t)p_hdr->i_size + p_hdr->i_add_size;
uint64_t i_size = (uint64_t)p_hdr->i_size + p_hdr->i_add_size;
assert( i_size >= 0 );
while( i_size > 0 )
{
int i_skip = __MIN( i_size, INT_MAX );
......@@ -444,7 +441,7 @@ static int SkipFile( stream_t *s,const rar_block_t *p_hdr )
int i_min_size = 7+21;
if( p_hdr->i_flags & RAR_BLOCK_FILE_HAS_HIGH )
i_min_size += 8;
if( p_hdr->i_size < i_min_size )
if( p_hdr->i_size < (unsigned)i_min_size )
return VLC_EGENERIC;
if( stream_Peek( s->p_source, &p_peek, i_min_size ) < i_min_size )
......@@ -481,7 +478,7 @@ static int SkipFile( stream_t *s,const rar_block_t *p_hdr )
}
/* Ignore smaller files */
const int64_t i_file_size = ((int64_t)i_file_size_high << 32) | i_file_size_low;
const uint64_t i_file_size = ((uint64_t)i_file_size_high << 32) | i_file_size_low;
if( p_sys->p_file &&
p_sys->p_file->i_size < i_file_size )
{
......
......@@ -2186,7 +2186,7 @@ static bool Control( input_thread_t *p_input,
else if( bookmark.i_byte_offset >= 0 &&
p_input->p->input.p_stream )
{
const int64_t i_size = stream_Size( p_input->p->input.p_stream );
const uint64_t i_size = stream_Size( p_input->p->input.p_stream );
if( i_size > 0 && bookmark.i_byte_offset <= i_size )
{
val.f_float = (double)bookmark.i_byte_offset / i_size;
......
......@@ -101,8 +101,8 @@ typedef struct
{
int64_t i_date;
int64_t i_start;
int64_t i_end;
uint64_t i_start;
uint64_t i_end;
uint8_t *p_buffer;
......@@ -111,7 +111,7 @@ typedef struct
typedef struct
{
char *psz_path;
int64_t i_size;
uint64_t i_size;
} access_entry_t;
......@@ -127,16 +127,16 @@ struct stream_sys_t
stream_read_method_t method; /* method to use */
int64_t i_pos; /* Current reading offset */
uint64_t i_pos; /* Current reading offset */
/* Method 1: pf_block */
struct
{
int64_t i_start; /* Offset of block for p_first */
int64_t i_offset; /* Offset for data in p_current */
uint64_t i_start; /* Offset of block for p_first */
uint64_t i_offset; /* Offset for data in p_current */
block_t *p_current; /* Current block */
int i_size; /* Total amount of data in the list */
uint64_t i_size; /* Total amount of data in the list */
block_t *p_first;
block_t **pp_last;
......@@ -145,16 +145,16 @@ struct stream_sys_t
/* Method 2: for pf_read */
struct
{
int i_offset; /* Buffer offset in the current track */
int i_tk; /* Current track */
unsigned i_offset; /* Buffer offset in the current track */
int i_tk; /* Current track */
stream_track_t tk[STREAM_CACHE_TRACK];
/* Global buffer */
uint8_t *p_buffer;
/* */
int i_used; /* Used since last read */
int i_read_size;
unsigned i_used; /* Used since last read */
unsigned i_read_size;
} stream;
......@@ -168,13 +168,13 @@ struct stream_sys_t
bool b_fastseek; /* From access */
/* Stat about reading data */
int64_t i_read_count;
int64_t i_bytes;
int64_t i_read_time;
uint64_t i_read_count;
uint64_t i_bytes;
uint64_t i_read_time;
/* Stat about seek */
int i_seek_count;
int64_t i_seek_time;
unsigned i_seek_count;
uint64_t i_seek_time;
} stat;
......@@ -188,14 +188,14 @@ struct stream_sys_t
/* Method 1: */
static int AStreamReadBlock( stream_t *s, void *p_read, unsigned int i_read );
static int AStreamPeekBlock( stream_t *s, const uint8_t **p_peek, unsigned int i_read );
static int AStreamSeekBlock( stream_t *s, int64_t i_pos );
static int AStreamSeekBlock( stream_t *s, uint64_t i_pos );
static void AStreamPrebufferBlock( stream_t *s );
static block_t *AReadBlock( stream_t *s, bool *pb_eof );
/* Method 2 */
static int AStreamReadStream( stream_t *s, void *p_read, unsigned int i_read );
static int AStreamPeekStream( stream_t *s, const uint8_t **pp_peek, unsigned int i_read );
static int AStreamSeekStream( stream_t *s, int64_t i_pos );
static int AStreamSeekStream( stream_t *s, uint64_t i_pos );
static void AStreamPrebufferStream( stream_t *s );
static int AReadStream( stream_t *s, void *p_read, unsigned int i_read );
......@@ -203,7 +203,7 @@ static int AReadStream( stream_t *s, void *p_read, unsigned int i_read );
static int AStreamControl( stream_t *s, int i_query, va_list );
static void AStreamDestroy( stream_t *s );
static void UStreamDestroy( stream_t *s );
static int ASeek( stream_t *s, int64_t i_pos );
static int ASeek( stream_t *s, uint64_t i_pos );
/****************************************************************************
* stream_CommonNew: create an empty stream structure
......@@ -578,14 +578,14 @@ static int AStreamControl( stream_t *s, int i_query, va_list args )
stream_sys_t *p_sys = s->p_sys;
access_t *p_access = p_sys->p_access;
bool *p_bool;
int64_t *pi_64, i_64;
int i_int;
bool *p_bool;
uint64_t *pi_64, i_64;
int i_int;
switch( i_query )
{
case STREAM_GET_SIZE:
pi_64 = (int64_t*)va_arg( args, int64_t * );
pi_64 = va_arg( args, uint64_t * );
if( s->p_sys->i_list )
{
int i;
......@@ -608,12 +608,12 @@ static int AStreamControl( stream_t *s, int i_query, va_list args )
break;
case STREAM_GET_POSITION:
pi_64 = (int64_t*)va_arg( args, int64_t * );
pi_64 = va_arg( args, uint64_t * );
*pi_64 = p_sys->i_pos;
break;
case STREAM_SET_POSITION:
i_64 = (int64_t)va_arg( args, int64_t );
i_64 = va_arg( args, uint64_t );
switch( p_sys->method )
{
case STREAM_METHOD_BLOCK:
......@@ -853,7 +853,7 @@ static int AStreamPeekBlock( stream_t *s, const uint8_t **pp_peek, unsigned int
return i_data;
}
static int AStreamSeekBlock( stream_t *s, int64_t i_pos )
static int AStreamSeekBlock( stream_t *s, uint64_t i_pos )
{
stream_sys_t *p_sys = s->p_sys;
access_t *p_access = p_sys->p_access;
......@@ -861,12 +861,12 @@ static int AStreamSeekBlock( stream_t *s, int64_t i_pos )
bool b_seek;
/* We already have thoses data, just update p_current/i_offset */
if( i_offset >= 0 && i_offset < p_sys->block.i_size )
if( i_offset >= 0 && (uint64_t)i_offset < p_sys->block.i_size )
{
block_t *b = p_sys->block.p_first;
int i_current = 0;
while( i_current + b->i_buffer < i_offset )
while( i_current + b->i_buffer < (uint64_t)i_offset )
{
i_current += b->i_buffer;
b = b->p_next;
......@@ -1059,7 +1059,7 @@ static int AStreamReadStream( stream_t *s, void *p_read, unsigned int i_read )
if( !p_read )
{
const int64_t i_pos_wanted = p_sys->i_pos + i_read;
const uint64_t i_pos_wanted = p_sys->i_pos + i_read;
if( AStreamSeekStream( s, i_pos_wanted ) )
{
......@@ -1075,7 +1075,7 @@ static int AStreamPeekStream( stream_t *s, const uint8_t **pp_peek, unsigned int
{
stream_sys_t *p_sys = s->p_sys;
stream_track_t *tk = &p_sys->stream.tk[p_sys->stream.i_tk];
int64_t i_off;
uint64_t i_off;
if( tk->i_start >= tk->i_end ) return 0; /* EOF */
......@@ -1090,19 +1090,21 @@ static int AStreamPeekStream( stream_t *s, const uint8_t **pp_peek, unsigned int
if( i_read > STREAM_CACHE_TRACK_SIZE / 2 )
i_read = STREAM_CACHE_TRACK_SIZE / 2;
while( tk->i_end - tk->i_start - p_sys->stream.i_offset < i_read )
while( tk->i_end < tk->i_start + p_sys->stream.i_offset + i_read )
{
if( p_sys->stream.i_used <= 1 )
{
/* Be sure we will read something */
p_sys->stream.i_used += i_read -
(tk->i_end - tk->i_start - p_sys->stream.i_offset);
p_sys->stream.i_used += tk->i_start + p_sys->stream.i_offset + i_read - tk->i_end;
}
if( AStreamRefillStream( s ) ) break;
}
if( tk->i_end - tk->i_start - p_sys->stream.i_offset < i_read )
if( tk->i_end < tk->i_start + p_sys->stream.i_offset + i_read )
{
i_read = tk->i_end - tk->i_start - p_sys->stream.i_offset;
}
/* Now, direct pointer or a copy ? */
i_off = (tk->i_start + p_sys->stream.i_offset) % STREAM_CACHE_TRACK_SIZE;
......@@ -1132,7 +1134,7 @@ static int AStreamPeekStream( stream_t *s, const uint8_t **pp_peek, unsigned int
return i_read;
}
static int AStreamSeekStream( stream_t *s, int64_t i_pos )
static int AStreamSeekStream( stream_t *s, uint64_t i_pos )
{
stream_sys_t *p_sys = s->p_sys;
......@@ -1163,7 +1165,7 @@ static int AStreamSeekStream( stream_t *s, int64_t i_pos )
access_Control( p_access, ACCESS_CAN_FASTSEEK, &b_afastseek );
/* FIXME compute seek cost (instead of static 'stupid' value) */
int64_t i_skip_threshold;
uint64_t i_skip_threshold;
if( b_aseek )
i_skip_threshold = b_afastseek ? 128 : 3*p_sys->stream.i_read_size;
else
......@@ -1177,7 +1179,7 @@ static int AStreamSeekStream( stream_t *s, int64_t i_pos )
int i_tk_idx = -1;
/* Prefer the current track */
if( p_current->i_start <= i_pos && i_pos - p_current->i_end <= i_skip_threshold )
if( p_current->i_start <= i_pos && i_pos <= p_current->i_end + i_skip_threshold )
{
tk = p_current;
i_tk_idx = p_sys->stream.i_tk;
......@@ -1217,7 +1219,7 @@ static int AStreamSeekStream( stream_t *s, int64_t i_pos )
if( tk != p_current )
i_skip_threshold = 0;
if( tk->i_start <= i_pos && i_pos - tk->i_end <= i_skip_threshold )
if( tk->i_start <= i_pos && i_pos <= tk->i_end + i_skip_threshold )
{
#ifdef STREAM_DEBUG
msg_Err( s, "AStreamSeekStream: reusing %d start=%"PRId64
......@@ -1235,9 +1237,9 @@ static int AStreamSeekStream( stream_t *s, int64_t i_pos )
if( ASeek( s, tk->i_end ) )
return VLC_EGENERIC;
}
else
else if( i_pos > tk->i_end )
{
int64_t i_skip = i_pos - tk->i_end;
uint64_t i_skip = i_pos - tk->i_end;
while( i_skip > 0 )
{
const int i_read_max = __MIN( 10 * STREAM_READ_ATONCE, i_skip );
......@@ -1268,7 +1270,7 @@ static int AStreamSeekStream( stream_t *s, int64_t i_pos )
* - refilling threshold
* - how much to refill
*/
if( (tk->i_end - tk->i_start) - p_sys->stream.i_offset < p_sys->stream.i_read_size )
if( tk->i_end < tk->i_start + p_sys->stream.i_offset + p_sys->stream.i_read_size )
{
if( p_sys->stream.i_used < STREAM_READ_ATONCE / 2 )
p_sys->stream.i_used = STREAM_READ_ATONCE / 2;
......@@ -1299,11 +1301,10 @@ static int AStreamReadNoSeekStream( stream_t *s, void *p_read, unsigned int i_re
while( i_data < i_read )
{
int i_off = (tk->i_start + p_sys->stream.i_offset) %
STREAM_CACHE_TRACK_SIZE;
unsigned i_off = (tk->i_start + p_sys->stream.i_offset) % STREAM_CACHE_TRACK_SIZE;
unsigned int i_current =
__MAX(0,__MIN( tk->i_end - tk->i_start - p_sys->stream.i_offset,
STREAM_CACHE_TRACK_SIZE - i_off ));
__MIN( tk->i_end - tk->i_start - p_sys->stream.i_offset,
STREAM_CACHE_TRACK_SIZE - i_off );
int i_copy = __MIN( i_current, i_read - i_data );
if( i_copy <= 0 ) break; /* EOF */
......@@ -1324,11 +1325,11 @@ static int AStreamReadNoSeekStream( stream_t *s, void *p_read, unsigned int i_re
/* */
p_sys->stream.i_used += i_copy;
if( tk->i_end - tk->i_start - p_sys->stream.i_offset <= i_read -i_data )
if( tk->i_end + i_data <= tk->i_start + p_sys->stream.i_offset + i_read )
{
const int i_read_requested = __MAX( __MIN( i_read - i_data,
STREAM_READ_ATONCE * 10 ),
STREAM_READ_ATONCE / 2 );
const unsigned i_read_requested = __MAX( __MIN( i_read - i_data,
STREAM_READ_ATONCE * 10 ),
STREAM_READ_ATONCE / 2 );
if( p_sys->stream.i_used < i_read_requested )
p_sys->stream.i_used = i_read_requested;
......@@ -1393,9 +1394,9 @@ static int AStreamRefillStream( stream_t *s )
tk->i_end += i_read;
/* Windows of STREAM_CACHE_TRACK_SIZE */
if( tk->i_end - tk->i_start > STREAM_CACHE_TRACK_SIZE )
if( tk->i_start + STREAM_CACHE_TRACK_SIZE < tk->i_end )
{
int i_invalid = tk->i_end - tk->i_start - STREAM_CACHE_TRACK_SIZE;
unsigned i_invalid = tk->i_end - tk->i_start - STREAM_CACHE_TRACK_SIZE;
tk->i_start += i_invalid;
p_sys->stream.i_offset -= i_invalid;
......@@ -1451,7 +1452,7 @@ static void AStreamPrebufferStream( stream_t *s )
/* */
i_read = STREAM_CACHE_TRACK_SIZE - i_buffered;
i_read = __MIN( p_sys->stream.i_read_size, i_read );
i_read = __MIN( (int)p_sys->stream.i_read_size, i_read );
i_read = AReadStream( s, &tk->p_buffer[i_buffered], i_read );
if( i_read < 0 )
continue;
......@@ -1829,11 +1830,10 @@ static block_t *AReadBlock( stream_t *s, bool *pb_eof )
return p_block;
}
static int ASeek( stream_t *s, int64_t i_pos )
static int ASeek( stream_t *s, uint64_t i_pos )
{
stream_sys_t *p_sys = s->p_sys;
access_t *p_access = p_sys->p_access;
assert( i_pos >= 0 );
/* Check which stream we need to access */
if( p_sys->i_list )
......
......@@ -24,6 +24,7 @@
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <limits.h>
#include "demux.h"
#include <libvlc.h>
......@@ -38,7 +39,7 @@ struct stream_sys_t
block_fifo_t *p_fifo;
block_t *p_block;
int64_t i_pos;
uint64_t i_pos;
/* Demuxer */
char *psz_name;
......@@ -223,13 +224,13 @@ static int DStreamPeek( stream_t *s, const uint8_t **pp_peek, unsigned int i_pee
static int DStreamControl( stream_t *s, int i_query, va_list args )
{
stream_sys_t *p_sys = s->p_sys;
int64_t *p_i64;
uint64_t *p_i64;
bool *p_b;
switch( i_query )
{
case STREAM_GET_SIZE:
p_i64 = (int64_t*) va_arg( args, int64_t * );
p_i64 = va_arg( args, uint64_t * );
*p_i64 = 0;
return VLC_SUCCESS;
......@@ -244,21 +245,22 @@ static int DStreamControl( stream_t *s, int i_query, va_list args )
return VLC_SUCCESS;
case STREAM_GET_POSITION:
p_i64 = (int64_t*) va_arg( args, int64_t * );
p_i64 = va_arg( args, uint64_t * );
*p_i64 = p_sys->i_pos;
return VLC_SUCCESS;
case STREAM_SET_POSITION:
{
int64_t i64 = (int64_t)va_arg( args, int64_t );
int i_skip;
if( i64 < p_sys->i_pos ) return VLC_EGENERIC;
i_skip = i64 - p_sys->i_pos;
uint64_t i64 = va_arg( args, uint64_t );
if( i64 < p_sys->i_pos )
return VLC_EGENERIC;
uint64_t i_skip = i64 - p_sys->i_pos;
while( i_skip > 0 )
{
int i_read = DStreamRead( s, NULL, (long)i_skip );
if( i_read <= 0 ) return VLC_EGENERIC;
int i_read = DStreamRead( s, NULL, __MIN(i_skip, INT_MAX) );
if( i_read <= 0 )
return VLC_EGENERIC;
i_skip -= i_read;
}
return VLC_SUCCESS;
......
......@@ -30,8 +30,8 @@
struct stream_sys_t
{
bool i_preserve_memory;
int64_t i_pos; /* Current reading offset */
int64_t i_size;
uint64_t i_pos; /* Current reading offset */
uint64_t i_size;
uint8_t *p_buffer;
};
......@@ -51,7 +51,7 @@ static void Delete ( stream_t * );
* pointed to by p_buffer is freed on stream_Destroy
*/
stream_t *__stream_MemoryNew( vlc_object_t *p_this, uint8_t *p_buffer,
int64_t i_size, bool i_preserve_memory )
uint64_t i_size, bool i_preserve_memory )
{
stream_t *s = stream_CommonNew( p_this );
stream_sys_t *p_sys;
......@@ -103,13 +103,13 @@ static int Control( stream_t *s, int i_query, va_list args )
stream_sys_t *p_sys = s->p_sys;
bool *p_bool;
int64_t *pi_64, i_64;
uint64_t *pi_64, i_64;
int i_int;
switch( i_query )
{
case STREAM_GET_SIZE:
pi_64 = (int64_t*)va_arg( args, int64_t * );
pi_64 = va_arg( args, uint64_t * );
*pi_64 = p_sys->i_size;
break;
......@@ -124,13 +124,12 @@ static int Control( stream_t *s, int i_query, va_list args )
break;
case STREAM_GET_POSITION:
pi_64 = (int64_t*)va_arg( args, int64_t * );
pi_64 = va_arg( args, uint64_t * );
*pi_64 = p_sys->i_pos;
break;
case STREAM_SET_POSITION:
i_64 = (int64_t)va_arg( args, int64_t );
i_64 = __MAX( i_64, 0 );
i_64 = va_arg( args, uint64_t );
i_64 = __MIN( i_64, s->p_sys->i_size );
p_sys->i_pos = i_64;
break;
......
......@@ -561,7 +561,7 @@ error:
static int ExecuteLoad( vlm_t *p_vlm, const char *psz_url, vlm_message_t **pp_status )
{
stream_t *p_stream = stream_UrlNew( p_vlm, psz_url );
int64_t i_size;
uint64_t i_size;
char *psz_buffer;
if( !p_stream )
......@@ -580,6 +580,8 @@ static int ExecuteLoad( vlm_t *p_vlm, const char *psz_url, vlm_message_t **pp_st
}
i_size = stream_Size( p_stream );
if( i_size > SIZE_MAX - 1 )
i_size = SIZE_MAX - 1;
psz_buffer = malloc( i_size + 1 );
if( !psz_buffer )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment