****************************************************************************/
static int ASF_ReadObjectCommon( stream_t *s, asf_object_t *p_obj )
{
- asf_object_common_t *p_common = (asf_object_common_t*)p_obj;
+ asf_object_common_t *p_common = &p_obj->common;
const uint8_t *p_peek;
if( stream_Peek( s, &p_peek, 24 ) < 24 )
static int ASF_ReadObject_Header( stream_t *s, asf_object_t *p_obj )
{
- asf_object_header_t *p_hdr = (asf_object_header_t*)p_obj;
+ asf_object_header_t *p_hdr = &p_obj->header;
asf_object_t *p_subobj;
int i_peek;
const uint8_t *p_peek;
{
p_subobj = malloc( sizeof( asf_object_t ) );
- if( ASF_ReadObject( s, p_subobj, (asf_object_t*)p_hdr ) )
+ if( !p_subobj || ASF_ReadObject( s, p_subobj, (asf_object_t*)p_hdr ) )
{
free( p_subobj );
break;
static int ASF_ReadObject_Data( stream_t *s, asf_object_t *p_obj )
{
- asf_object_data_t *p_data = (asf_object_data_t*)p_obj;
+ asf_object_data_t *p_data = &p_obj->data;
int i_peek;
const uint8_t *p_peek;
static int ASF_ReadObject_Index( stream_t *s, asf_object_t *p_obj )
{
- asf_object_index_t *p_index = (asf_object_index_t*)p_obj;
+ asf_object_index_t *p_index = &p_obj->index;
const uint8_t *p_peek;
- int i;
+ unsigned int i;
/* We just ignore error on the index */
if( stream_Peek( s, &p_peek, p_index->i_object_size ) <
- __MAX( (int)p_index->i_object_size, 56 ) )
+ __MAX( (int64_t)p_index->i_object_size, 56 ) )
return VLC_SUCCESS;
ASF_GetGUID( &p_index->i_file_id, p_peek + 24 );
p_index->index_entry = calloc( p_index->i_index_entry_count,
sizeof(asf_index_entry_t) );
+ if( !p_index->index_entry )
+ return VLC_ENOMEM;
- for( i = 0, p_peek += 56; i < (int)p_index->i_index_entry_count;
- i++, p_peek += 6 )
+ for( i = 0, p_peek += 56; i < p_index->i_index_entry_count; i++, p_peek += 6 )
{
p_index->index_entry[i].i_packet_number = GetDWLE( p_peek );
p_index->index_entry[i].i_packet_count = GetDWLE( p_peek + 4 );
static void ASF_FreeObject_Index( asf_object_t *p_obj )
{
- asf_object_index_t *p_index = (asf_object_index_t*)p_obj;
+ asf_object_index_t *p_index = &p_obj->index;
FREENULL( p_index->index_entry );
}
static int ASF_ReadObject_file_properties( stream_t *s, asf_object_t *p_obj )
{
- asf_object_file_properties_t *p_fp = (asf_object_file_properties_t*)p_obj;
+ asf_object_file_properties_t *p_fp = &p_obj->file_properties;
int i_peek;
const uint8_t *p_peek;
static void ASF_FreeObject_metadata( asf_object_t *p_obj )
{
- asf_object_metadata_t *p_meta =
- (asf_object_metadata_t *)p_obj;
+ asf_object_metadata_t *p_meta = &p_obj->metadata;
unsigned int i;
for( i = 0; i < p_meta->i_record_entries_count; i++ )
static int ASF_ReadObject_metadata( stream_t *s, asf_object_t *p_obj )
{
- asf_object_metadata_t *p_meta =
- (asf_object_metadata_t *)p_obj;
+ asf_object_metadata_t *p_meta = &p_obj->metadata;
int i_peek;
unsigned int i;
#endif
if( ( i_peek = stream_Peek( s, &p_peek, p_meta->i_object_size ) ) <
- __MAX( (int)p_meta->i_object_size, 26 ) )
+ __MAX( (int64_t)p_meta->i_object_size, 26 ) )
return VLC_EGENERIC;
p_meta->i_record_entries_count = GetWLE( p_peek + 24 );
p_meta->record = calloc( p_meta->i_record_entries_count,
sizeof(asf_metadata_record_t) );
+ if( !p_meta->record )
+ return VLC_ENOMEM;
for( i = 0; i < p_meta->i_record_entries_count; i++ )
{
{
p_record->p_data = malloc( i_data );
p_record->i_data = i_data;
- if( i_data > 0 )
+ if( p_record->p_data && i_data > 0 )
memcpy( p_record->p_data, p_data, i_data );
p_data += i_data;
static int ASF_ReadObject_header_extension( stream_t *s, asf_object_t *p_obj )
{
- asf_object_header_extension_t *p_he =
- (asf_object_header_extension_t *)p_obj;
+ asf_object_header_extension_t *p_he = &p_obj->header_extension;
int i_peek;
const uint8_t *p_peek;
p_he->i_header_extension_size = GetDWLE( p_peek + 42 );
if( p_he->i_header_extension_size )
{
- if( i_peek-46 < (int)p_he->i_header_extension_size )
+ if( (unsigned int)(i_peek-46) < p_he->i_header_extension_size )
return VLC_EGENERIC;
p_he->p_header_extension_data =
{
asf_object_t *p_obj = malloc( sizeof( asf_object_t ) );
- if( ASF_ReadObject( s, p_obj, (asf_object_t*)p_he ) )
+ if( !p_obj || ASF_ReadObject( s, p_obj, (asf_object_t*)p_he ) )
{
free( p_obj );
break;
static void ASF_FreeObject_header_extension( asf_object_t *p_obj )
{
- asf_object_header_extension_t *p_he =
- (asf_object_header_extension_t *)p_obj;
+ asf_object_header_extension_t *p_he = &p_obj->header_extension;
FREENULL( p_he->p_header_extension_data );
}
static int ASF_ReadObject_stream_properties( stream_t *s, asf_object_t *p_obj )
{
- asf_object_stream_properties_t *p_sp =
- (asf_object_stream_properties_t*)p_obj;
+ asf_object_stream_properties_t *p_sp = &p_obj->stream_properties;
size_t i_peek;
const uint8_t *p_peek;
p_sp->p_type_specific_data =
malloc( p_sp->i_type_specific_data_length );
- if( p_sp->p_type_specific_data == NULL )
+ if( !p_sp->p_type_specific_data )
return VLC_ENOMEM;
memcpy( p_sp->p_type_specific_data, p_peek + 78,
p_sp->i_type_specific_data_length );
i_peek -= p_sp->i_type_specific_data_length;
}
- else
- {
- p_sp->p_type_specific_data = NULL;
- }
if( p_sp->i_error_correction_data_length )
{
p_sp->p_error_correction_data =
malloc( p_sp->i_error_correction_data_length );
- if( p_sp->p_error_correction_data == NULL )
+ if( !p_sp->p_error_correction_data )
{
free( p_sp->p_type_specific_data );
return VLC_ENOMEM;
p_peek + 78 + p_sp->i_type_specific_data_length,
p_sp->i_error_correction_data_length );
}
- else
- {
- p_sp->p_error_correction_data = NULL;
- }
#ifdef ASF_DEBUG
msg_Dbg( s,
static void ASF_FreeObject_stream_properties( asf_object_t *p_obj )
{
- asf_object_stream_properties_t *p_sp =
- (asf_object_stream_properties_t*)p_obj;
+ asf_object_stream_properties_t *p_sp = &p_obj->stream_properties;
FREENULL( p_sp->p_type_specific_data );
FREENULL( p_sp->p_error_correction_data );
static int ASF_ReadObject_codec_list( stream_t *s, asf_object_t *p_obj )
{
- asf_object_codec_list_t *p_cl = (asf_object_codec_list_t*)p_obj;
+ asf_object_codec_list_t *p_cl = &p_obj->codec_list;
int i_peek;
const uint8_t *p_peek, *p_data;
if( p_codec->i_information_length > 0 && ASF_HAVE( p_codec->i_information_length ) )
{
p_codec->p_information = malloc( p_codec->i_information_length );
- memcpy( p_codec->p_information, p_data, p_codec->i_information_length );
+ if( p_codec->p_information )
+ memcpy( p_codec->p_information, p_data, p_codec->i_information_length );
+ else
+ p_codec->i_information_length = 0;
p_data += p_codec->i_information_length;
}
- else
- {
- p_codec->p_information = NULL;
- }
}
p_cl->i_codec_entries_count = i_codec;
}
static void ASF_FreeObject_codec_list( asf_object_t *p_obj )
{
- asf_object_codec_list_t *p_cl = (asf_object_codec_list_t*)p_obj;
+ asf_object_codec_list_t *p_cl = &p_obj->codec_list;
unsigned int i_codec;
for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ )
* and for the some others object, length give char16 count ... */
static int ASF_ReadObject_content_description(stream_t *s, asf_object_t *p_obj)
{
- asf_object_content_description_t *p_cd =
- (asf_object_content_description_t *)p_obj;
+ asf_object_content_description_t *p_cd = &p_obj->content_description;
const uint8_t *p_peek, *p_data;
int i_peek, i_title, i_artist, i_copyright, i_description, i_rating;
vlc_iconv_t cd = (vlc_iconv_t)-1;
}
/* FIXME i_size*3 is the worst case. */
-#define GETSTRINGW( psz_str, i_size ) \
- psz_str = (char *)calloc( i_size*3+1, sizeof( char ) ); \
- ib = (const char *)p_data; \
- ob = psz_str; \
- i_ibl = i_size; \
- i_obl = i_size*3; \
- i_len = vlc_iconv(cd, &ib, &i_ibl, &ob, &i_obl); \
- p_data += i_size;
+#define GETSTRINGW( psz_str, i_size ) do { \
+ psz_str = calloc( i_size*3+1, sizeof(char) ); \
+ if( psz_str ) { \
+ ib = (const char *)p_data; \
+ ob = psz_str; \
+ i_ibl = i_size; \
+ i_obl = i_size*3; \
+ i_len = vlc_iconv(cd, &ib, &i_ibl, &ob, &i_obl); \
+ p_data += i_size; \
+ } } while(0)
p_data = p_peek + 24;
static void ASF_FreeObject_content_description( asf_object_t *p_obj)
{
- asf_object_content_description_t *p_cd =
- (asf_object_content_description_t *)p_obj;
+ asf_object_content_description_t *p_cd = &p_obj->content_description;
FREENULL( p_cd->psz_title );
FREENULL( p_cd->psz_artist );
/* Language list: */
static int ASF_ReadObject_language_list(stream_t *s, asf_object_t *p_obj)
{
- asf_object_language_list_t *p_ll =
- (asf_object_language_list_t*)p_obj;
+ asf_object_language_list_t *p_ll = &p_obj->language_list;
const uint8_t *p_peek, *p_data;
int i_peek;
int i;
if( p_ll->i_language > 0 )
{
p_ll->ppsz_language = calloc( p_ll->i_language, sizeof( char *) );
+ if( !p_ll->ppsz_language )
+ return VLC_ENOMEM;
for( i = 0; i < p_ll->i_language; i++ )
{
static void ASF_FreeObject_language_list( asf_object_t *p_obj)
{
- asf_object_language_list_t *p_ll =
- (asf_object_language_list_t *)p_obj;
+ asf_object_language_list_t *p_ll = &p_obj->language_list;
int i;
for( i = 0; i < p_ll->i_language; i++ )
static int ASF_ReadObject_stream_bitrate_properties( stream_t *s,
asf_object_t *p_obj)
{
- asf_object_stream_bitrate_properties_t *p_sb =
- (asf_object_stream_bitrate_properties_t *)p_obj;
+ asf_object_stream_bitrate_properties_t *p_sb = &p_obj->stream_bitrate;
const uint8_t *p_peek, *p_data;
int i_peek;
int i;
static int ASF_ReadObject_extended_stream_properties( stream_t *s,
asf_object_t *p_obj)
{
- asf_object_extended_stream_properties_t *p_esp =
- (asf_object_extended_stream_properties_t*)p_obj;
+ asf_object_extended_stream_properties_t *p_esp = &p_obj->ext_stream;
const uint8_t *p_peek, *p_data;
int i_peek, i;
sizeof(int) );
p_esp->ppsz_stream_name = calloc( p_esp->i_stream_name_count,
sizeof(char*) );
+ if( !p_esp->pi_stream_name_language ||
+ !p_esp->ppsz_stream_name )
+ {
+ free( p_esp->pi_stream_name_language );
+ free( p_esp->ppsz_stream_name );
+ return VLC_ENOMEM;
+ }
for( i = 0; i < p_esp->i_stream_name_count; i++ )
{
if( !ASF_HAVE( 2+2 ) )
p_sp = malloc( sizeof( asf_object_t ) );
- if( ASF_ReadObject( s, p_sp, NULL ) )
+ if( !p_sp || ASF_ReadObject( s, p_sp, NULL ) )
{
free( p_sp );
}
}
static void ASF_FreeObject_extended_stream_properties( asf_object_t *p_obj)
{
- asf_object_extended_stream_properties_t *p_esp =
- (asf_object_extended_stream_properties_t *)p_obj;
+ asf_object_extended_stream_properties_t *p_esp = &p_obj->ext_stream;
int i;
for( i = 0; i < p_esp->i_stream_name_count; i++ )
static int ASF_ReadObject_advanced_mutual_exclusion( stream_t *s,
asf_object_t *p_obj)
{
- asf_object_advanced_mutual_exclusion_t *p_ae =
- (asf_object_advanced_mutual_exclusion_t *)p_obj;
+ asf_object_advanced_mutual_exclusion_t *p_ae = &p_obj->advanced_mutual_exclusion;
const uint8_t *p_peek, *p_data;
int i_peek;
int i;
}
static void ASF_FreeObject_advanced_mutual_exclusion( asf_object_t *p_obj)
{
- asf_object_advanced_mutual_exclusion_t *p_ae =
- (asf_object_advanced_mutual_exclusion_t *)p_obj;
+ asf_object_advanced_mutual_exclusion_t *p_ae = &p_obj->advanced_mutual_exclusion;
FREENULL( p_ae->pi_stream_number );
}
static int ASF_ReadObject_stream_prioritization( stream_t *s,
asf_object_t *p_obj)
{
- asf_object_stream_prioritization_t *p_sp =
- (asf_object_stream_prioritization_t *)p_obj;
+ asf_object_stream_prioritization_t *p_sp = &p_obj->stream_prioritization;
const uint8_t *p_peek, *p_data;
int i_peek;
int i;
p_sp->pi_priority_stream_number =
calloc( p_sp->i_priority_count, sizeof(int) );
+ if( !p_sp->pi_priority_flag || !p_sp->pi_priority_stream_number )
+ {
+ free( p_sp->pi_priority_flag );
+ free( p_sp->pi_priority_stream_number );
+ return VLC_ENOMEM;
+ }
+
for( i = 0; i < p_sp->i_priority_count; i++ )
{
if( !ASF_HAVE(2+2) )
}
static void ASF_FreeObject_stream_prioritization( asf_object_t *p_obj)
{
- asf_object_stream_prioritization_t *p_sp =
- (asf_object_stream_prioritization_t *)p_obj;
+ asf_object_stream_prioritization_t *p_sp = &p_obj->stream_prioritization;
FREENULL( p_sp->pi_priority_stream_number );
FREENULL( p_sp->pi_priority_flag );
asf_object_t *p_obj)
{
asf_object_extended_content_description_t *p_ec =
- (asf_object_extended_content_description_t *)p_obj;
+ &p_obj->extended_content_description;
const uint8_t *p_peek, *p_data;
int i_peek;
int i;
int j;
p_ec->ppsz_value[i] = malloc( 2*i_size + 1 );
- for( j = 0; j < i_size; j++ )
+ if( p_ec->ppsz_value[i] )
{
- const uint8_t v = ASF_READ1();
- p_ec->ppsz_value[i][2*j+0] = hex[v>>4];
- p_ec->ppsz_value[i][2*j+1] = hex[v&0xf];
+ char *psz_value = p_ec->ppsz_value[i];
+ for( j = 0; j < i_size; j++ )
+ {
+ const uint8_t v = ASF_READ1();
+ psz_value[2*j+0] = hex[v>>4];
+ psz_value[2*j+1] = hex[v&0xf];
+ }
+ psz_value[2*i_size] = '\0';
}
- p_ec->ppsz_value[i][2*i_size] = '\0';
}
else if( i_type == 2 )
{
else if( i_type == 3 )
{
/* DWord */
- asprintf( &p_ec->ppsz_value[i], "%d", ASF_READ4() );
+ if( asprintf( &p_ec->ppsz_value[i], "%d", ASF_READ4() ) == -1 )
+ p_ec->ppsz_value[i] = NULL;
}
else if( i_type == 4 )
{
/* QWord */
- asprintf( &p_ec->ppsz_value[i], "%"PRId64, ASF_READ8() );
+ if( asprintf( &p_ec->ppsz_value[i], "%"PRId64, ASF_READ8() ) == -1 )
+ p_ec->ppsz_value[i] = NULL;
}
else if( i_type == 5 )
{
/* Word */
- asprintf( &p_ec->ppsz_value[i], "%d", ASF_READ2() );
+ if( asprintf( &p_ec->ppsz_value[i], "%d", ASF_READ2() ) == -1 )
+ p_ec->ppsz_value[i] = NULL;
}
else
{
static void ASF_FreeObject_extended_content_description( asf_object_t *p_obj)
{
asf_object_extended_content_description_t *p_ec =
- (asf_object_extended_content_description_t *)p_obj;
+ &p_obj->extended_content_description;
int i;
for( i = 0; i < p_ec->i_count; i++ )
/* */
-static struct
+static const struct
{
const guid_t *p_id;
int i_type;
asf_object_root_t *p_root = malloc( sizeof( asf_object_root_t ) );
asf_object_t *p_obj;
+ if( !p_root )
+ return NULL;
+
p_root->i_type = ASF_OBJECT_ROOT;
memcpy( &p_root->i_object_id, &asf_object_null_guid, sizeof( guid_t ) );
p_root->i_object_pos = stream_Tell( s );
{
p_obj = malloc( sizeof( asf_object_t ) );
- if( ASF_ReadObject( s, p_obj, (asf_object_t*)p_root ) )
+ if( !p_obj || ASF_ReadObject( s, p_obj, (asf_object_t*)p_root ) )
{
free( p_obj );
break;