Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc-2-2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc-2-2
Commits
59c9e830
Commit
59c9e830
authored
Apr 27, 2013
by
Denis Charmet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add try/catch when reading elements with libmatroska.
parent
6053dcfa
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
370 additions
and
253 deletions
+370
-253
modules/demux/mkv/demux.cpp
modules/demux/mkv/demux.cpp
+21
-6
modules/demux/mkv/matroska_segment.cpp
modules/demux/mkv/matroska_segment.cpp
+257
-209
modules/demux/mkv/matroska_segment_parse.cpp
modules/demux/mkv/matroska_segment_parse.cpp
+92
-38
No files found.
modules/demux/mkv/demux.cpp
View file @
59c9e830
...
@@ -464,16 +464,24 @@ matroska_stream_c *demux_sys_t::AnalyseAllSegmentsFound( demux_t *p_demux, EbmlS
...
@@ -464,16 +464,24 @@ matroska_stream_c *demux_sys_t::AnalyseAllSegmentsFound( demux_t *p_demux, EbmlS
EbmlElement
*
p_l0
,
*
p_l1
,
*
p_l2
;
EbmlElement
*
p_l0
,
*
p_l1
,
*
p_l2
;
bool
b_keep_stream
=
false
,
b_keep_segment
=
false
;
bool
b_keep_stream
=
false
,
b_keep_segment
=
false
;
/
/ verify the EBML Header
/
* verify the EBML Header... it shouldn't be bigger than 1kB */
p_l0
=
p_estream
->
FindNextID
(
EBML_INFO
(
EbmlHead
),
UINT64_MAX
);
p_l0
=
p_estream
->
FindNextID
(
EBML_INFO
(
EbmlHead
),
1024
);
if
(
p_l0
==
NULL
)
if
(
p_l0
==
NULL
)
{
{
msg_Err
(
p_demux
,
"No EBML header found"
);
msg_Err
(
p_demux
,
"No EBML header found"
);
return
NULL
;
return
NULL
;
}
}
// verify we can read this Segment, we only support Matroska version 1 for now
/* verify we can read this Segment */
try
{
p_l0
->
Read
(
*
p_estream
,
EBML_CLASS_CONTEXT
(
EbmlHead
),
i_upper_lvl
,
p_l0
,
true
);
p_l0
->
Read
(
*
p_estream
,
EBML_CLASS_CONTEXT
(
EbmlHead
),
i_upper_lvl
,
p_l0
,
true
);
}
catch
(...)
{
msg_Err
(
p_demux
,
"EBML Header Read failed"
);
return
NULL
;
}
EDocType
doc_type
=
GetChild
<
EDocType
>
(
*
static_cast
<
EbmlHead
*>
(
p_l0
));
EDocType
doc_type
=
GetChild
<
EDocType
>
(
*
static_cast
<
EbmlHead
*>
(
p_l0
));
if
(
std
::
string
(
doc_type
)
!=
"matroska"
&&
std
::
string
(
doc_type
)
!=
"webm"
)
if
(
std
::
string
(
doc_type
)
!=
"matroska"
&&
std
::
string
(
doc_type
)
!=
"webm"
)
...
@@ -519,8 +527,15 @@ matroska_stream_c *demux_sys_t::AnalyseAllSegmentsFound( demux_t *p_demux, EbmlS
...
@@ -519,8 +527,15 @@ matroska_stream_c *demux_sys_t::AnalyseAllSegmentsFound( demux_t *p_demux, EbmlS
// find the families of this segment
// find the families of this segment
KaxInfo
*
p_info
=
static_cast
<
KaxInfo
*>
(
p_l1
);
KaxInfo
*
p_info
=
static_cast
<
KaxInfo
*>
(
p_l1
);
b_keep_segment
=
b_initial
;
b_keep_segment
=
b_initial
;
try
{
p_info
->
Read
(
*
p_estream
,
EBML_CLASS_CONTEXT
(
KaxInfo
),
i_upper_lvl
,
p_l2
,
true
);
p_info
->
Read
(
*
p_estream
,
EBML_CLASS_CONTEXT
(
KaxInfo
),
i_upper_lvl
,
p_l2
,
true
);
}
catch
(...)
{
msg_Err
(
p_demux
,
"KaxInfo found but corrupted"
);
break
;
}
for
(
size_t
i
=
0
;
i
<
p_info
->
ListSize
();
i
++
)
for
(
size_t
i
=
0
;
i
<
p_info
->
ListSize
();
i
++
)
{
{
EbmlElement
*
l
=
(
*
p_info
)[
i
];
EbmlElement
*
l
=
(
*
p_info
)[
i
];
...
...
modules/demux/mkv/matroska_segment.cpp
View file @
59c9e830
...
@@ -106,6 +106,7 @@ matroska_segment_c::~matroska_segment_c()
...
@@ -106,6 +106,7 @@ matroska_segment_c::~matroska_segment_c()
*****************************************************************************/
*****************************************************************************/
void
matroska_segment_c
::
LoadCues
(
KaxCues
*
cues
)
void
matroska_segment_c
::
LoadCues
(
KaxCues
*
cues
)
{
{
bool
b_invalid_cue
;
EbmlParser
*
ep
;
EbmlParser
*
ep
;
EbmlElement
*
el
;
EbmlElement
*
el
;
...
@@ -120,6 +121,7 @@ void matroska_segment_c::LoadCues( KaxCues *cues )
...
@@ -120,6 +121,7 @@ void matroska_segment_c::LoadCues( KaxCues *cues )
{
{
if
(
MKV_IS_ID
(
el
,
KaxCuePoint
)
)
if
(
MKV_IS_ID
(
el
,
KaxCuePoint
)
)
{
{
b_invalid_cue
=
false
;
#define idx p_indexes[i_index]
#define idx p_indexes[i_index]
idx
.
i_track
=
-
1
;
idx
.
i_track
=
-
1
;
...
@@ -134,14 +136,23 @@ void matroska_segment_c::LoadCues( KaxCues *cues )
...
@@ -134,14 +136,23 @@ void matroska_segment_c::LoadCues( KaxCues *cues )
if
(
MKV_IS_ID
(
el
,
KaxCueTime
)
)
if
(
MKV_IS_ID
(
el
,
KaxCueTime
)
)
{
{
KaxCueTime
&
ctime
=
*
(
KaxCueTime
*
)
el
;
KaxCueTime
&
ctime
=
*
(
KaxCueTime
*
)
el
;
try
{
ctime
.
ReadData
(
es
.
I_O
()
);
ctime
.
ReadData
(
es
.
I_O
()
);
}
catch
(...)
{
msg_Err
(
&
sys
.
demuxer
,
"Error while reading CueTime"
);
b_invalid_cue
=
true
;
break
;
}
idx
.
i_time
=
uint64
(
ctime
)
*
i_timescale
/
(
mtime_t
)
1000
;
idx
.
i_time
=
uint64
(
ctime
)
*
i_timescale
/
(
mtime_t
)
1000
;
}
}
else
if
(
MKV_IS_ID
(
el
,
KaxCueTrackPositions
)
)
else
if
(
MKV_IS_ID
(
el
,
KaxCueTrackPositions
)
)
{
{
ep
->
Down
();
ep
->
Down
();
try
{
while
(
(
el
=
ep
->
Get
()
)
!=
NULL
)
while
(
(
el
=
ep
->
Get
()
)
!=
NULL
)
{
{
if
(
MKV_IS_ID
(
el
,
KaxCueTrack
)
)
if
(
MKV_IS_ID
(
el
,
KaxCueTrack
)
)
...
@@ -170,6 +181,14 @@ void matroska_segment_c::LoadCues( KaxCues *cues )
...
@@ -170,6 +181,14 @@ void matroska_segment_c::LoadCues( KaxCues *cues )
msg_Dbg
(
&
sys
.
demuxer
,
" * Unknown (%s)"
,
typeid
(
*
el
).
name
()
);
msg_Dbg
(
&
sys
.
demuxer
,
" * Unknown (%s)"
,
typeid
(
*
el
).
name
()
);
}
}
}
}
}
catch
(...)
{
ep
->
Up
();
msg_Err
(
&
sys
.
demuxer
,
"Error while reading %s"
,
typeid
(
*
el
).
name
()
);
b_invalid_cue
=
true
;
break
;
}
ep
->
Up
();
ep
->
Up
();
}
}
else
else
...
@@ -184,7 +203,8 @@ void matroska_segment_c::LoadCues( KaxCues *cues )
...
@@ -184,7 +203,8 @@ void matroska_segment_c::LoadCues( KaxCues *cues )
" track=%d bnum=%d", idx.i_time, idx.i_position,
" track=%d bnum=%d", idx.i_time, idx.i_position,
idx.i_track, idx.i_block_number );
idx.i_track, idx.i_block_number );
#endif
#endif
if
(
likely
(
!
b_invalid_cue
)
)
{
i_index
++
;
i_index
++
;
if
(
i_index
>=
i_index_max
)
if
(
i_index
>=
i_index_max
)
{
{
...
@@ -192,6 +212,7 @@ void matroska_segment_c::LoadCues( KaxCues *cues )
...
@@ -192,6 +212,7 @@ void matroska_segment_c::LoadCues( KaxCues *cues )
p_indexes
=
(
mkv_index_t
*
)
xrealloc
(
p_indexes
,
p_indexes
=
(
mkv_index_t
*
)
xrealloc
(
p_indexes
,
sizeof
(
mkv_index_t
)
*
i_index_max
);
sizeof
(
mkv_index_t
)
*
i_index_max
);
}
}
}
#undef idx
#undef idx
}
}
else
else
...
@@ -245,6 +266,8 @@ SimpleTag * matroska_segment_c::ParseSimpleTags( KaxTagSimple *tag, int target_t
...
@@ -245,6 +266,8 @@ SimpleTag * matroska_segment_c::ParseSimpleTags( KaxTagSimple *tag, int target_t
sys
.
meta
=
vlc_meta_New
();
sys
.
meta
=
vlc_meta_New
();
msg_Dbg
(
&
sys
.
demuxer
,
"| + Simple Tag "
);
msg_Dbg
(
&
sys
.
demuxer
,
"| + Simple Tag "
);
try
{
while
(
(
el
=
ep
->
Get
()
)
!=
NULL
)
while
(
(
el
=
ep
->
Get
()
)
!=
NULL
)
{
{
if
(
MKV_IS_ID
(
el
,
KaxTagName
)
)
if
(
MKV_IS_ID
(
el
,
KaxTagName
)
)
...
@@ -280,6 +303,14 @@ SimpleTag * matroska_segment_c::ParseSimpleTags( KaxTagSimple *tag, int target_t
...
@@ -280,6 +303,14 @@ SimpleTag * matroska_segment_c::ParseSimpleTags( KaxTagSimple *tag, int target_t
}
}
/*TODO Handle binary tags*/
/*TODO Handle binary tags*/
}
}
}
catch
(...)
{
msg_Err
(
&
sys
.
demuxer
,
"Error while reading Tag "
);
delete
ep
;
delete
p_simple
;
return
NULL
;
}
delete
ep
;
delete
ep
;
if
(
!
p_simple
->
psz_tag_name
||
!
p_simple
->
p_value
)
if
(
!
p_simple
->
psz_tag_name
||
!
p_simple
->
p_value
)
...
@@ -342,6 +373,8 @@ void matroska_segment_c::LoadTags( KaxTags *tags )
...
@@ -342,6 +373,8 @@ void matroska_segment_c::LoadTags( KaxTags *tags )
msg_Dbg
(
&
sys
.
demuxer
,
"| + Targets"
);
msg_Dbg
(
&
sys
.
demuxer
,
"| + Targets"
);
ep
->
Down
();
ep
->
Down
();
while
(
(
el
=
ep
->
Get
()
)
!=
NULL
)
while
(
(
el
=
ep
->
Get
()
)
!=
NULL
)
{
try
{
{
if
(
MKV_IS_ID
(
el
,
KaxTagTargetTypeValue
)
)
if
(
MKV_IS_ID
(
el
,
KaxTagTargetTypeValue
)
)
{
{
...
@@ -385,7 +418,14 @@ void matroska_segment_c::LoadTags( KaxTags *tags )
...
@@ -385,7 +418,14 @@ void matroska_segment_c::LoadTags( KaxTags *tags )
msg_Dbg
(
&
sys
.
demuxer
,
"| | + AttachmentUID: %"
PRIu64
,
p_tag
->
i_uid
);
msg_Dbg
(
&
sys
.
demuxer
,
"| | + AttachmentUID: %"
PRIu64
,
p_tag
->
i_uid
);
}
}
}
}
catch
(...)
{
msg_Err
(
&
sys
.
demuxer
,
"Error while reading tag"
);
ep
->
Up
();
ep
->
Up
();
break
;
}
ep
->
Up
();
}
}
}
else
if
(
MKV_IS_ID
(
el
,
KaxTagSimple
)
)
else
if
(
MKV_IS_ID
(
el
,
KaxTagSimple
)
)
{
{
...
@@ -1227,6 +1267,8 @@ int matroska_segment_c::BlockGet( KaxBlock * & pp_block, KaxSimpleBlock * & pp_s
...
@@ -1227,6 +1267,8 @@ int matroska_segment_c::BlockGet( KaxBlock * & pp_block, KaxSimpleBlock * & pp_s
}
}
/* do parsing */
/* do parsing */
try
{
switch
(
i_level
)
switch
(
i_level
)
{
{
case
1
:
case
1
:
...
@@ -1332,6 +1374,12 @@ int matroska_segment_c::BlockGet( KaxBlock * & pp_block, KaxSimpleBlock * & pp_s
...
@@ -1332,6 +1374,12 @@ int matroska_segment_c::BlockGet( KaxBlock * & pp_block, KaxSimpleBlock * & pp_s
return
VLC_EGENERIC
;
return
VLC_EGENERIC
;
}
}
}
}
catch
(...)
{
msg_Err
(
&
sys
.
demuxer
,
"Error while reading %s... upping level"
,
typeid
(
*
el
).
name
());
ep
->
Up
();
}
}
}
}
SimpleTag
::~
SimpleTag
()
SimpleTag
::~
SimpleTag
()
...
...
modules/demux/mkv/matroska_segment_parse.cpp
View file @
59c9e830
...
@@ -86,6 +86,8 @@ void matroska_segment_c::ParseSeekHead( KaxSeekHead *seekhead )
...
@@ -86,6 +86,8 @@ void matroska_segment_c::ParseSeekHead( KaxSeekHead *seekhead )
msg_Dbg
(
&
sys
.
demuxer
,
"| | + Seek"
);
msg_Dbg
(
&
sys
.
demuxer
,
"| | + Seek"
);
#endif
#endif
ep
->
Down
();
ep
->
Down
();
try
{
while
(
(
l
=
ep
->
Get
()
)
!=
NULL
)
while
(
(
l
=
ep
->
Get
()
)
!=
NULL
)
{
{
if
(
MKV_IS_ID
(
l
,
KaxSeekID
)
)
if
(
MKV_IS_ID
(
l
,
KaxSeekID
)
)
...
@@ -106,6 +108,11 @@ void matroska_segment_c::ParseSeekHead( KaxSeekHead *seekhead )
...
@@ -106,6 +108,11 @@ void matroska_segment_c::ParseSeekHead( KaxSeekHead *seekhead )
msg_Dbg
(
&
sys
.
demuxer
,
"| | + Unknown (%s)"
,
typeid
(
*
l
).
name
()
);
msg_Dbg
(
&
sys
.
demuxer
,
"| | + Unknown (%s)"
,
typeid
(
*
l
).
name
()
);
}
}
}
}
}
catch
(...)
{
msg_Err
(
&
sys
.
demuxer
,
"Error while reading %s"
,
typeid
(
*
l
).
name
()
);
}
ep
->
Up
();
ep
->
Up
();
if
(
i_pos
>=
0
)
if
(
i_pos
>=
0
)
...
@@ -713,7 +720,15 @@ void matroska_segment_c::ParseTracks( KaxTracks *tracks )
...
@@ -713,7 +720,15 @@ void matroska_segment_c::ParseTracks( KaxTracks *tracks )
int
i_upper_level
=
0
;
int
i_upper_level
=
0
;
/* Master elements */
/* Master elements */
try
{
tracks
->
Read
(
es
,
EBML_CONTEXT
(
tracks
),
i_upper_level
,
el
,
true
);
tracks
->
Read
(
es
,
EBML_CONTEXT
(
tracks
),
i_upper_level
,
el
,
true
);
}
catch
(...)
{
msg_Err
(
&
sys
.
demuxer
,
"Couldn't read tracks"
);
return
;
}
for
(
size_t
i
=
0
;
i
<
tracks
->
ListSize
();
i
++
)
for
(
size_t
i
=
0
;
i
<
tracks
->
ListSize
();
i
++
)
{
{
...
@@ -741,7 +756,15 @@ void matroska_segment_c::ParseInfo( KaxInfo *info )
...
@@ -741,7 +756,15 @@ void matroska_segment_c::ParseInfo( KaxInfo *info )
/* Master elements */
/* Master elements */
m
=
static_cast
<
EbmlMaster
*>
(
info
);
m
=
static_cast
<
EbmlMaster
*>
(
info
);
try
{
m
->
Read
(
es
,
EBML_CONTEXT
(
info
),
i_upper_level
,
el
,
true
);
m
->
Read
(
es
,
EBML_CONTEXT
(
info
),
i_upper_level
,
el
,
true
);
}
catch
(...)
{
msg_Err
(
&
sys
.
demuxer
,
"Couldn't read info"
);
return
;
}
for
(
size_t
i
=
0
;
i
<
m
->
ListSize
();
i
++
)
for
(
size_t
i
=
0
;
i
<
m
->
ListSize
();
i
++
)
{
{
...
@@ -854,9 +877,11 @@ void matroska_segment_c::ParseInfo( KaxInfo *info )
...
@@ -854,9 +877,11 @@ void matroska_segment_c::ParseInfo( KaxInfo *info )
else
if
(
MKV_IS_ID
(
l
,
KaxChapterTranslate
)
)
else
if
(
MKV_IS_ID
(
l
,
KaxChapterTranslate
)
)
{
{
KaxChapterTranslate
*
p_trans
=
static_cast
<
KaxChapterTranslate
*>
(
l
);
KaxChapterTranslate
*
p_trans
=
static_cast
<
KaxChapterTranslate
*>
(
l
);
try
{
p_trans
->
Read
(
es
,
EBML_CONTEXT
(
p_trans
),
i_upper_level
,
el
,
true
);
chapter_translation_c
*
p_translate
=
new
chapter_translation_c
();
chapter_translation_c
*
p_translate
=
new
chapter_translation_c
();
p_trans
->
Read
(
es
,
EBML_CONTEXT
(
p_trans
),
i_upper_level
,
el
,
true
);
for
(
size_t
j
=
0
;
j
<
p_trans
->
ListSize
();
j
++
)
for
(
size_t
j
=
0
;
j
<
p_trans
->
ListSize
();
j
++
)
{
{
EbmlElement
*
l
=
(
*
p_trans
)[
j
];
EbmlElement
*
l
=
(
*
p_trans
)[
j
];
...
@@ -877,6 +902,11 @@ void matroska_segment_c::ParseInfo( KaxInfo *info )
...
@@ -877,6 +902,11 @@ void matroska_segment_c::ParseInfo( KaxInfo *info )
translations
.
push_back
(
p_translate
);
translations
.
push_back
(
p_translate
);
}
}
catch
(...)
{
msg_Err
(
&
sys
.
demuxer
,
"Error while reading Chapter Tranlate"
);
}
}
else
else
{
{
msg_Dbg
(
&
sys
.
demuxer
,
"| | + Unknown (%s)"
,
typeid
(
*
l
).
name
()
);
msg_Dbg
(
&
sys
.
demuxer
,
"| | + Unknown (%s)"
,
typeid
(
*
l
).
name
()
);
...
@@ -1039,7 +1069,15 @@ void matroska_segment_c::ParseAttachments( KaxAttachments *attachments )
...
@@ -1039,7 +1069,15 @@ void matroska_segment_c::ParseAttachments( KaxAttachments *attachments )
EbmlElement
*
el
;
EbmlElement
*
el
;
int
i_upper_level
=
0
;
int
i_upper_level
=
0
;
try
{
attachments
->
Read
(
es
,
EBML_CONTEXT
(
attachments
),
i_upper_level
,
el
,
true
);
attachments
->
Read
(
es
,
EBML_CONTEXT
(
attachments
),
i_upper_level
,
el
,
true
);
}
catch
(...)
{
msg_Err
(
&
sys
.
demuxer
,
"Error while reading attachments"
);
return
;
}
KaxAttached
*
attachedFile
=
FindChild
<
KaxAttached
>
(
*
attachments
);
KaxAttached
*
attachedFile
=
FindChild
<
KaxAttached
>
(
*
attachments
);
...
@@ -1089,7 +1127,15 @@ void matroska_segment_c::ParseChapters( KaxChapters *chapters )
...
@@ -1089,7 +1127,15 @@ void matroska_segment_c::ParseChapters( KaxChapters *chapters )
int
i_upper_level
=
0
;
int
i_upper_level
=
0
;
/* Master elements */
/* Master elements */
try
{
chapters
->
Read
(
es
,
EBML_CONTEXT
(
chapters
),
i_upper_level
,
el
,
true
);
chapters
->
Read
(
es
,
EBML_CONTEXT
(
chapters
),
i_upper_level
,
el
,
true
);
}
catch
(...)
{
msg_Err
(
&
sys
.
demuxer
,
"Error while reading chapters"
);
return
;
}
for
(
size_t
i
=
0
;
i
<
chapters
->
ListSize
();
i
++
)
for
(
size_t
i
=
0
;
i
<
chapters
->
ListSize
();
i
++
)
{
{
...
@@ -1150,7 +1196,15 @@ void matroska_segment_c::ParseCluster( bool b_update_start_time )
...
@@ -1150,7 +1196,15 @@ void matroska_segment_c::ParseCluster( bool b_update_start_time )
/* Master elements */
/* Master elements */
m
=
static_cast
<
EbmlMaster
*>
(
cluster
);
m
=
static_cast
<
EbmlMaster
*>
(
cluster
);
try
{
m
->
Read
(
es
,
EBML_CONTEXT
(
cluster
),
i_upper_level
,
el
,
true
);
m
->
Read
(
es
,
EBML_CONTEXT
(
cluster
),
i_upper_level
,
el
,
true
);
}
catch
(...)
{
msg_Err
(
&
sys
.
demuxer
,
"Error while reading cluster"
);
return
;
}
for
(
unsigned
int
i
=
0
;
i
<
m
->
ListSize
();
i
++
)
for
(
unsigned
int
i
=
0
;
i
<
m
->
ListSize
();
i
++
)
{
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment