* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
#include <vlc/vlc.h>
-#include <stdio.h>
-#include <stdlib.h> /* malloc(), free() */
#include <vlc_demux.h>
/****************************************************************************
* GUID functions
****************************************************************************/
-void ASF_GetGUID( guid_t *p_guid, uint8_t *p_data )
+void ASF_GetGUID( guid_t *p_guid, const uint8_t *p_data )
{
p_guid->v1 = GetDWLE( p_data );
p_guid->v2 = GetWLE( p_data + 4);
static int ASF_ReadObjectCommon( stream_t *s, asf_object_t *p_obj )
{
asf_object_common_t *p_common = (asf_object_common_t*)p_obj;
- uint8_t *p_peek;
+ const uint8_t *p_peek;
if( stream_Peek( s, &p_peek, 24 ) < 24 )
{
static void ASF_FreeObject_Null( asf_object_t *pp_obj )
{
+ VLC_UNUSED(pp_obj);
return;
}
asf_object_header_t *p_hdr = (asf_object_header_t*)p_obj;
asf_object_t *p_subobj;
int i_peek;
- uint8_t *p_peek;
+ const uint8_t *p_peek;
if( ( i_peek = stream_Peek( s, &p_peek, 30 ) ) < 30 )
{
{
asf_object_data_t *p_data = (asf_object_data_t*)p_obj;
int i_peek;
- uint8_t *p_peek;
+ const uint8_t *p_peek;
if( ( i_peek = stream_Peek( s, &p_peek, 50 ) ) < 50 )
{
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;
- int i_peek;
- uint8_t *p_peek;
+ const uint8_t *p_peek;
+ int i;
- if( ( i_peek = stream_Peek( s, &p_peek, 56 ) ) < 56 )
+ if( stream_Peek( s, &p_peek, p_index->i_object_size ) <
+ (int)p_index->i_object_size )
{
- return VLC_EGENERIC;
+ /* Just ignore */
+ return VLC_SUCCESS;
}
+
ASF_GetGUID( &p_index->i_file_id, p_peek + 24 );
p_index->i_index_entry_time_interval = GetQWLE( p_peek + 40 );
p_index->i_max_packet_count = GetDWLE( p_peek + 48 );
p_index->i_index_entry_count = GetDWLE( p_peek + 52 );
- p_index->index_entry = NULL; /* FIXME */
+ p_index->index_entry = NULL;
#ifdef ASF_DEBUG
msg_Dbg( s,
(long int)p_index->i_index_entry_count );
#endif
+ /* Sanity checking */
+ if( p_index->i_index_entry_count > (p_index->i_object_size - 56) / 6 )
+ p_index->i_index_entry_count = (p_index->i_object_size - 56) / 6;
+
+ p_index->index_entry = malloc( sizeof(asf_index_entry_t) *
+ p_index->i_index_entry_count );
+
+ for( i = 0, p_peek += 56; i < (int)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 );
+ }
+
return VLC_SUCCESS;
}
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;
- int i_peek;
- uint8_t *p_peek;
+ int i_peek;
+ const uint8_t *p_peek;
- if( ( i_peek = stream_Peek( s, &p_peek, 92) ) < 92 )
+ if( ( i_peek = stream_Peek( s, &p_peek, 104 ) ) < 104 )
{
return VLC_EGENERIC;
}
p_fp->i_file_size = GetQWLE( p_peek + 40 );
p_fp->i_creation_date = GetQWLE( p_peek + 48 );
p_fp->i_data_packets_count = GetQWLE( p_peek + 56 );
- p_fp->i_play_duration = GetQWLE( p_peek + 64 );
- p_fp->i_send_duration = GetQWLE( p_peek + 72 );
- p_fp->i_preroll = GetQWLE( p_peek + 80 );
+ p_fp->i_send_duration = GetQWLE( p_peek + 64 );
+ p_fp->i_play_duration = GetQWLE( p_peek + 72 );
+ p_fp->i_preroll = GetDWLE( p_peek + 80 );
+ p_fp->i_unknown = GetDWLE( p_peek + 84 );
p_fp->i_flags = GetDWLE( p_peek + 88 );
p_fp->i_min_data_packet_size = GetDWLE( p_peek + 92 );
p_fp->i_max_data_packet_size = GetDWLE( p_peek + 96 );
msg_Dbg( s,
"read \"file properties object\" file_id:" GUID_FMT
" file_size:"I64Fd" creation_date:"I64Fd" data_packets_count:"
- I64Fd" play_duration:"I64Fd" send_duration:"I64Fd" preroll:"
- I64Fd" flags:%d min_data_packet_size:%d max_data_packet_size:%d "
- "max_bitrate:%d",
+ I64Fd" send_duration:"I64Fd" play_duration:"I64Fd" preroll:%d"
+ "unknown:%d flags:%d min_data_packet_size:%d "
+ "max_data_packet_size:%d max_bitrate:%d",
GUID_PRINT( p_fp->i_file_id ), p_fp->i_file_size,
p_fp->i_creation_date, p_fp->i_data_packets_count,
- p_fp->i_play_duration, p_fp->i_send_duration,
- p_fp->i_preroll, p_fp->i_flags,
+ p_fp->i_send_duration, p_fp->i_play_duration,
+ p_fp->i_preroll, p_fp->i_unknown, p_fp->i_flags,
p_fp->i_min_data_packet_size, p_fp->i_max_data_packet_size,
p_fp->i_max_bitrate );
#endif
for( i = 0; i < p_meta->i_record_entries_count; i++ )
{
- if( p_meta->record[i].psz_name ) free( p_meta->record[i].psz_name );
- if( p_meta->record[i].p_data ) free( p_meta->record[i].p_data );
+ free( p_meta->record[i].psz_name );
+ free( p_meta->record[i].p_data );
}
- if( p_meta->record ) free( p_meta->record );
+ free( p_meta->record );
}
static int ASF_ReadObject_metadata( stream_t *s, asf_object_t *p_obj )
(asf_object_metadata_t *)p_obj;
int i_peek, i_entries, i;
- uint8_t *p_peek;
+ const uint8_t *p_peek;
#ifdef ASF_DEBUG
unsigned int j;
#endif
asf_object_header_extension_t *p_he =
(asf_object_header_extension_t *)p_obj;
int i_peek;
- uint8_t *p_peek;
+ const uint8_t *p_peek;
if( ( i_peek = stream_Peek( s, &p_peek, p_he->i_object_size ) ) < 46)
{
{
asf_object_stream_properties_t *p_sp =
(asf_object_stream_properties_t*)p_obj;
- int i_peek;
- uint8_t *p_peek;
+ size_t i_peek;
+ const uint8_t *p_peek;
- if( ( i_peek = stream_Peek( s, &p_peek, p_sp->i_object_size ) ) < 74 )
+ if( ( i_peek = stream_Peek( s, &p_peek, p_sp->i_object_size ) ) < 78 )
{
return VLC_EGENERIC;
}
+
ASF_GetGUID( &p_sp->i_stream_type, p_peek + 24 );
ASF_GetGUID( &p_sp->i_error_correction_type, p_peek + 40 );
p_sp->i_time_offset = GetQWLE( p_peek + 56 );
p_sp->i_flags = GetWLE( p_peek + 72 );
p_sp->i_stream_number = p_sp->i_flags&0x07f;
p_sp->i_reserved = GetDWLE( p_peek + 74 );
+ i_peek -= 78;
+
if( p_sp->i_type_specific_data_length )
{
+ if( i_peek < p_sp->i_type_specific_data_length )
+ return VLC_EGENERIC;
+
p_sp->p_type_specific_data =
malloc( p_sp->i_type_specific_data_length );
+ if( p_sp->p_type_specific_data == NULL )
+ 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 )
{
+ if( i_peek < p_sp->i_error_correction_data_length )
+ {
+ free( p_sp->p_type_specific_data );
+ return VLC_EGENERIC;
+ }
+
p_sp->p_error_correction_data =
malloc( p_sp->i_error_correction_data_length );
+ if( p_sp->p_error_correction_data == NULL )
+ {
+ free( p_sp->p_type_specific_data );
+ return VLC_ENOMEM;
+ }
memcpy( p_sp->p_error_correction_data,
p_peek + 78 + p_sp->i_type_specific_data_length,
p_sp->i_error_correction_data_length );
{
asf_object_codec_list_t *p_cl = (asf_object_codec_list_t*)p_obj;
int i_peek;
- uint8_t *p_peek, *p_data;
+ const uint8_t *p_peek, *p_data;
unsigned int i_codec;
{
asf_object_content_description_t *p_cd =
(asf_object_content_description_t *)p_obj;
- uint8_t *p_peek, *p_data;
+ 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;
const char *ib = NULL;
{
asf_object_language_list_t *p_ll =
(asf_object_language_list_t*)p_obj;
- uint8_t *p_peek, *p_data;
+ const uint8_t *p_peek, *p_data;
int i_peek;
int i;
}
#ifdef ASF_DEBUG
- msg_Dbg( s, "read \"language list object\" %d entries",
+ msg_Dbg( s, "read \"language list object\" %d entries",
p_ll->i_language );
for( i = 0; i < p_ll->i_language; i++ )
- msg_Dbg( s, " - '%s'",
+ msg_Dbg( s, " - '%s'",
p_ll->ppsz_language[i] );
#endif
return VLC_SUCCESS;
{
asf_object_stream_bitrate_properties_t *p_sb =
(asf_object_stream_bitrate_properties_t *)p_obj;
- uint8_t *p_peek, *p_data;
+ const uint8_t *p_peek, *p_data;
int i_peek;
int i;
{
msg_Dbg( s," - stream=%d bitrate=%d",
p_sb->bitrate[i].i_stream_number,
- p_sb->bitrate[i].i_avg_bitrate );
+ p_sb->bitrate[i].i_avg_bitrate );
}
#endif
return VLC_SUCCESS;
{
asf_object_extended_stream_properties_t *p_esp =
(asf_object_extended_stream_properties_t*)p_obj;
- uint8_t *p_peek, *p_data;
+ const uint8_t *p_peek, *p_data;
int i_peek, i;
if( ( i_peek = stream_Peek( s, &p_peek, p_esp->i_object_size ) ) < 88 )
asf_object_t *p_sp;
/* Cannot fail as peek succeed */
stream_Read( s, NULL, p_data - p_peek );
-
+
p_sp = malloc( sizeof( asf_object_t ) );
if( ASF_ReadObject( s, p_sp, NULL ) )
{
asf_object_advanced_mutual_exclusion_t *p_ae =
(asf_object_advanced_mutual_exclusion_t *)p_obj;
- uint8_t *p_peek, *p_data;
+ const uint8_t *p_peek, *p_data;
int i_peek;
int i;
p_ae->pi_stream_number[i] = GetWLE( p_data );
p_data += 2;
}
-
+
#ifdef ASF_DEBUG
msg_Dbg( s, "read \"advanced mutual exclusion object\"" );
for( i = 0; i < p_ae->i_stream_number_count; i++ )
{
asf_object_stream_prioritization_t *p_sp =
(asf_object_stream_prioritization_t *)p_obj;
- uint8_t *p_peek, *p_data;
+ const uint8_t *p_peek, *p_data;
int i_peek;
int i;
{
asf_object_extended_content_description_t *p_ec =
(asf_object_extended_content_description_t *)p_obj;
- uint8_t *p_peek, *p_data;
+ const uint8_t *p_peek, *p_data;
int i_peek;
int i;
p_ec->ppsz_value[i] = NULL;
p_data += i_size;
-
+
#undef GETSTRINGW
{
asf_object_XXX_t *p_XX =
(asf_object_XXX_t *)p_obj;
- uint8_t *p_peek, *p_data;
+ const uint8_t *p_peek;
+ uint8_t *p_data;
int i_peek;
if( ( i_peek = stream_Peek( s, &p_peek, p_XX->i_object_size ) ) < XXX )
}
/* link this object with father */
- if( p_father )
+ if( p_father && ! i_result )
{
if( p_father->common.p_first )
{
static const struct
{
const guid_t *p_id;
- char *psz_name;
+ const char *psz_name;
} ASF_ObjectDumpDebugInfo[] =
{
{ &asf_object_header_guid, "Header" },
char str[1024];
int i;
union asf_object_u *p_child;
- char *psz_name;
+ const char *psz_name;
/* Find the name */
for( i = 0; ASF_ObjectDumpDebugInfo[i].p_id != NULL; i++ )