Commit a7466071 authored by Laurent Aimar's avatar Laurent Aimar

Changed ASF_ReadObject_metadata to work like other functions.

parent 8770fee8
...@@ -312,98 +312,99 @@ static int ASF_ReadObject_metadata( stream_t *s, asf_object_t *p_obj ) ...@@ -312,98 +312,99 @@ static int ASF_ReadObject_metadata( stream_t *s, asf_object_t *p_obj )
asf_object_metadata_t *p_meta = asf_object_metadata_t *p_meta =
(asf_object_metadata_t *)p_obj; (asf_object_metadata_t *)p_obj;
int i_peek, i_entries, i; int i_peek;
const uint8_t *p_peek; unsigned int i;
const uint8_t *p_peek, *p_data;
#ifdef ASF_DEBUG #ifdef ASF_DEBUG
unsigned int j; unsigned int j;
#endif #endif
if( stream_Peek( s, &p_peek, p_meta->i_object_size ) < if( ( i_peek = stream_Peek( s, &p_peek, p_meta->i_object_size ) ) <
__MAX( (int)p_meta->i_object_size, 26 ) ) __MAX( (int)p_meta->i_object_size, 26 ) )
return VLC_EGENERIC; return VLC_EGENERIC;
p_meta->i_record_entries_count = 0; p_meta->i_record_entries_count = GetWLE( p_peek + 24 );
p_meta->record = NULL;
p_data = p_peek + 26;
i_peek = 24; p_meta->record = calloc( p_meta->i_record_entries_count,
i_entries = GetWLE( p_peek + i_peek ); i_peek += 2; sizeof(asf_metadata_record_t) );
for( i = 0; i < i_entries && i_peek < (int)p_meta->i_object_size -12; i++ )
for( i = 0; i < p_meta->i_record_entries_count; i++ )
{ {
asf_metadata_record_t record; asf_metadata_record_t *p_record = &p_meta->record[i];
int i_name, i_data, j; int i_name;
int i_data;
int j;
if( GetWLE( p_peek + i_peek ) != 0 ) if( &p_data[2+2+2+2+4] > &p_peek[i_peek] )
{ break;
ASF_FreeObject_metadata( p_obj );
return VLC_EGENERIC;
}
i_peek += 2; if( GetWLE( p_data ) != 0 )
record.i_stream = GetWLE( p_peek + i_peek ); i_peek += 2; break;
i_name = GetWLE( p_peek + i_peek ); i_peek += 2; p_data += 2;
record.i_type = GetWLE( p_peek + i_peek ); i_peek += 2;
i_data = GetDWLE( p_peek + i_peek ); i_peek += 4;
if( record.i_type > ASF_METADATA_TYPE_WORD || p_record->i_stream = GetWLE( p_data ); p_data += 2;
i_peek + i_data + i_name > (int)p_meta->i_object_size ) i_name = GetWLE( p_data ); p_data += 2;
{ p_record->i_type = GetWLE( p_data ); p_data += 2;
ASF_FreeObject_metadata( p_obj ); i_data = GetDWLE( p_data ); p_data += 4;
return VLC_EGENERIC;
}
record.i_val = 0; if( &p_data[i_name+i_data] > &p_peek[i_peek] )
record.i_data = 0; break;
record.p_data = 0;
/* get name */ /* Read name */
record.psz_name = malloc( i_name/2 + 1 ); p_record->psz_name = malloc( i_name/2 + 1 );
for( j = 0; j < i_name/2; j++ ) for( j = 0; j < i_name/2; j++ )
{ {
record.psz_name[j] = GetWLE( p_peek + i_peek ); i_peek += 2; p_record->psz_name[j] = GetWLE( p_data ); p_data += 2;
} }
record.psz_name[j] = 0; /* just to make sure */ p_record->psz_name[j] = 0;
/* get data */ /* Read data */
if( record.i_type == ASF_METADATA_TYPE_STRING ) if( p_record->i_type == ASF_METADATA_TYPE_STRING )
{ {
record.p_data = malloc( i_data/2 + 1 ); p_record->p_data = malloc( i_data/2 + 1 );
record.i_data = i_data/2; p_record->i_data = i_data/2; /* FIXME Is that needed ? */
for( j = 0; j < i_data/2; j++ ) for( j = 0; j < i_data/2; j++ )
{ {
record.p_data[j] = GetWLE( p_peek + i_peek ); i_peek += 2; p_record->p_data[j] = GetWLE( &p_data[2*j] );
} }
record.p_data[j] = 0; /* just to make sure */ p_record->p_data[j] = 0; /* just to make sure */
p_data += i_data;
} }
else if( record.i_type == ASF_METADATA_TYPE_BYTE ) else if( p_record->i_type == ASF_METADATA_TYPE_BYTE )
{ {
record.p_data = malloc( i_data ); p_record->p_data = malloc( i_data );
record.i_data = i_data; p_record->i_data = i_data;
memcpy( record.p_data, p_peek + i_peek, i_data ); if( i_data > 0 )
p_peek += i_data; memcpy( p_record->p_data, p_data, i_data );
p_data += i_data;
}
else if( p_record->i_type == ASF_METADATA_TYPE_QWORD )
{
p_record->i_val = GetQWLE( p_data ); p_data += 8;
}
else if( p_record->i_type == ASF_METADATA_TYPE_DWORD )
{
p_record->i_val = GetDWLE( p_data ); p_data += 4;
}
else if( p_record->i_type == ASF_METADATA_TYPE_WORD )
{
p_record->i_val = GetWLE( p_data ); p_data += 2;
}
else if( p_record->i_type == ASF_METADATA_TYPE_BOOL )
{
p_record->i_val = GetWLE( p_data ); p_data += 2;
} }
else else
{ {
if( record.i_type == ASF_METADATA_TYPE_QWORD ) /* Unknown */
{ p_data += i_data;
record.i_val = GetQWLE( p_peek + i_peek ); i_peek += 8;
}
else if( record.i_type == ASF_METADATA_TYPE_DWORD )
{
record.i_val = GetDWLE( p_peek + i_peek ); i_peek += 4;
}
else
{
record.i_val = GetWLE( p_peek + i_peek ); i_peek += 2;
}
} }
p_meta->i_record_entries_count++;
p_meta->record =
realloc( p_meta->record, p_meta->i_record_entries_count *
sizeof(asf_metadata_record_t) );
memcpy( &p_meta->record[p_meta->i_record_entries_count-1],
&record, sizeof(asf_metadata_record_t) );
} }
p_meta->i_record_entries_count = i;
#ifdef ASF_DEBUG #ifdef ASF_DEBUG
msg_Dbg( s, msg_Dbg( s,
...@@ -597,12 +598,14 @@ static int ASF_ReadObject_codec_list( stream_t *s, asf_object_t *p_obj ) ...@@ -597,12 +598,14 @@ static int ASF_ReadObject_codec_list( stream_t *s, asf_object_t *p_obj )
ASF_GetGUID( &p_cl->i_reserved, p_peek + 24 ); ASF_GetGUID( &p_cl->i_reserved, p_peek + 24 );
p_cl->i_codec_entries_count = GetWLE( p_peek + 40 ); p_cl->i_codec_entries_count = GetWLE( p_peek + 40 );
p_data = p_peek + 44;
if( p_cl->i_codec_entries_count > 0 ) if( p_cl->i_codec_entries_count > 0 )
{ {
p_cl->codec = calloc( p_cl->i_codec_entries_count, p_cl->codec = calloc( p_cl->i_codec_entries_count,
sizeof( asf_codec_entry_t ) ); sizeof( asf_codec_entry_t ) );
p_data = p_peek + 44;
for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ ) for( i_codec = 0; i_codec < p_cl->i_codec_entries_count; i_codec++ )
{ {
asf_codec_entry_t *p_codec = &p_cl->codec[i_codec]; asf_codec_entry_t *p_codec = &p_cl->codec[i_codec];
......
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