Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
F
ffmpeg
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
ffmpeg
Commits
44cde38c
Commit
44cde38c
authored
Sep 12, 2017
by
Mark Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cbs: Always check for bitstream end before reading
parent
b05128f3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
62 deletions
+67
-62
cbs.c
libavcodec/cbs.c
+6
-0
cbs_h2645.c
libavcodec/cbs_h2645.c
+58
-60
cbs_mpeg2.c
libavcodec/cbs_mpeg2.c
+3
-2
No files found.
libavcodec/cbs.c
View file @
44cde38c
...
@@ -313,6 +313,12 @@ int ff_cbs_read_unsigned(CodedBitstreamContext *ctx, BitstreamContext *bc,
...
@@ -313,6 +313,12 @@ int ff_cbs_read_unsigned(CodedBitstreamContext *ctx, BitstreamContext *bc,
av_assert0
(
width
<=
32
);
av_assert0
(
width
<=
32
);
if
(
bitstream_bits_left
(
bc
)
<
width
)
{
av_log
(
ctx
->
log_ctx
,
AV_LOG_ERROR
,
"Invalid value at "
"%s: bitstream ended.
\n
"
,
name
);
return
AVERROR_INVALIDDATA
;
}
if
(
ctx
->
trace_enable
)
if
(
ctx
->
trace_enable
)
position
=
bitstream_tell
(
bc
);
position
=
bitstream_tell
(
bc
);
...
...
libavcodec/cbs_h2645.c
View file @
44cde38c
...
@@ -36,40 +36,39 @@ static int cbs_read_ue_golomb(CodedBitstreamContext *ctx, BitstreamContext *bc,
...
@@ -36,40 +36,39 @@ static int cbs_read_ue_golomb(CodedBitstreamContext *ctx, BitstreamContext *bc,
uint32_t
range_min
,
uint32_t
range_max
)
uint32_t
range_min
,
uint32_t
range_max
)
{
{
uint32_t
value
;
uint32_t
value
;
int
position
;
int
position
,
i
,
j
;
unsigned
int
k
;
char
bits
[
65
];
if
(
ctx
->
trace_enable
)
{
position
=
bitstream_tell
(
bc
);
char
bits
[
65
];
unsigned
int
k
;
int
i
,
j
;
position
=
bitstream_tell
(
bc
);
for
(
i
=
0
;
i
<
32
;
i
++
)
{
if
(
bitstream_bits_left
(
bc
)
<
i
+
1
)
{
for
(
i
=
0
;
i
<
32
;
i
++
)
{
av_log
(
ctx
->
log_ctx
,
AV_LOG_ERROR
,
"Invalid ue-golomb code at "
k
=
bitstream_read_bit
(
bc
);
"%s: bitstream ended.
\n
"
,
name
);
bits
[
i
]
=
k
?
'1'
:
'0'
;
if
(
k
)
break
;
}
if
(
i
>=
32
)
{
av_log
(
ctx
->
log_ctx
,
AV_LOG_ERROR
,
"Invalid ue-golomb "
"code found while reading %s: "
"more than 31 zeroes.
\n
"
,
name
);
return
AVERROR_INVALIDDATA
;
return
AVERROR_INVALIDDATA
;
}
}
value
=
1
;
k
=
bitstream_read_bit
(
bc
);
for
(
j
=
0
;
j
<
i
;
j
++
)
{
bits
[
i
]
=
k
?
'1'
:
'0'
;
k
=
bitstream_read_bit
(
bc
);
if
(
k
)
bits
[
i
+
j
+
1
]
=
k
?
'1'
:
'0'
;
break
;
value
=
value
<<
1
|
k
;
}
}
if
(
i
>=
32
)
{
bits
[
i
+
j
+
1
]
=
0
;
av_log
(
ctx
->
log_ctx
,
AV_LOG_ERROR
,
"Invalid ue-golomb code at "
--
value
;
"%s: more than 31 zeroes.
\n
"
,
name
);
return
AVERROR_INVALIDDATA
;
}
value
=
1
;
for
(
j
=
0
;
j
<
i
;
j
++
)
{
k
=
bitstream_read_bit
(
bc
);
bits
[
i
+
j
+
1
]
=
k
?
'1'
:
'0'
;
value
=
value
<<
1
|
k
;
}
bits
[
i
+
j
+
1
]
=
0
;
--
value
;
if
(
ctx
->
trace_enable
)
ff_cbs_trace_syntax_element
(
ctx
,
position
,
name
,
bits
,
value
);
ff_cbs_trace_syntax_element
(
ctx
,
position
,
name
,
bits
,
value
);
}
else
{
value
=
get_ue_golomb_long
(
bc
);
}
if
(
value
<
range_min
||
value
>
range_max
)
{
if
(
value
<
range_min
||
value
>
range_max
)
{
av_log
(
ctx
->
log_ctx
,
AV_LOG_ERROR
,
"%s out of range: "
av_log
(
ctx
->
log_ctx
,
AV_LOG_ERROR
,
"%s out of range: "
...
@@ -87,44 +86,43 @@ static int cbs_read_se_golomb(CodedBitstreamContext *ctx, BitstreamContext *bc,
...
@@ -87,44 +86,43 @@ static int cbs_read_se_golomb(CodedBitstreamContext *ctx, BitstreamContext *bc,
int32_t
range_min
,
int32_t
range_max
)
int32_t
range_min
,
int32_t
range_max
)
{
{
int32_t
value
;
int32_t
value
;
int
position
;
int
position
,
i
,
j
;
unsigned
int
k
;
uint32_t
v
;
char
bits
[
65
];
if
(
ctx
->
trace_enable
)
{
position
=
bitstream_tell
(
bc
);
char
bits
[
65
];
uint32_t
v
;
unsigned
int
k
;
int
i
,
j
;
position
=
bitstream_tell
(
bc
);
for
(
i
=
0
;
i
<
32
;
i
++
)
{
for
(
i
=
0
;
i
<
32
;
i
++
)
{
k
=
bitstream_read_bit
(
bc
);
if
(
bitstream_bits_left
(
bc
)
<
i
+
1
)
{
bits
[
i
]
=
k
?
'1'
:
'0'
;
av_log
(
ctx
->
log_ctx
,
AV_LOG_ERROR
,
"Invalid se-golomb code at "
if
(
k
)
"%s: bitstream ended.
\n
"
,
name
);
break
;
}
if
(
i
>=
32
)
{
av_log
(
ctx
->
log_ctx
,
AV_LOG_ERROR
,
"Invalid se-golomb "
"code found while reading %s: "
"more than 31 zeroes.
\n
"
,
name
);
return
AVERROR_INVALIDDATA
;
return
AVERROR_INVALIDDATA
;
}
}
v
=
1
;
k
=
bitstream_read_bit
(
bc
);
for
(
j
=
0
;
j
<
i
;
j
++
)
{
bits
[
i
]
=
k
?
'1'
:
'0'
;
k
=
bitstream_read_bit
(
bc
);
if
(
k
)
bits
[
i
+
j
+
1
]
=
k
?
'1'
:
'0'
;
break
;
v
=
v
<<
1
|
k
;
}
}
if
(
i
>=
32
)
{
bits
[
i
+
j
+
1
]
=
0
;
av_log
(
ctx
->
log_ctx
,
AV_LOG_ERROR
,
"Invalid se-golomb code at "
if
(
v
&
1
)
"%s: more than 31 zeroes.
\n
"
,
name
);
value
=
-
(
int32_t
)(
v
/
2
);
return
AVERROR_INVALIDDATA
;
else
}
value
=
v
/
2
;
v
=
1
;
for
(
j
=
0
;
j
<
i
;
j
++
)
{
k
=
bitstream_read_bit
(
bc
);
bits
[
i
+
j
+
1
]
=
k
?
'1'
:
'0'
;
v
=
v
<<
1
|
k
;
}
bits
[
i
+
j
+
1
]
=
0
;
if
(
v
&
1
)
value
=
-
(
int32_t
)(
v
/
2
);
else
value
=
v
/
2
;
if
(
ctx
->
trace_enable
)
ff_cbs_trace_syntax_element
(
ctx
,
position
,
name
,
bits
,
value
);
ff_cbs_trace_syntax_element
(
ctx
,
position
,
name
,
bits
,
value
);
}
else
{
value
=
get_se_golomb_long
(
bc
);
}
if
(
value
<
range_min
||
value
>
range_max
)
{
if
(
value
<
range_min
||
value
>
range_max
)
{
av_log
(
ctx
->
log_ctx
,
AV_LOG_ERROR
,
"%s out of range: "
av_log
(
ctx
->
log_ctx
,
AV_LOG_ERROR
,
"%s out of range: "
...
...
libavcodec/cbs_mpeg2.c
View file @
44cde38c
...
@@ -58,8 +58,9 @@
...
@@ -58,8 +58,9 @@
CHECK(ff_cbs_read_unsigned(ctx, rw, 1, "marker_bit", &one, 1, 1)); \
CHECK(ff_cbs_read_unsigned(ctx, rw, 1, "marker_bit", &one, 1, 1)); \
} while (0)
} while (0)
#define nextbits(width, compare, var) (var = bitstream_peek(rw, width), \
#define nextbits(width, compare, var) \
var == (compare))
(bitstream_bits_left(rw) >= width && \
(var = bitstream_peek(rw, width)) == (compare))
#include "cbs_mpeg2_syntax_template.c"
#include "cbs_mpeg2_syntax_template.c"
...
...
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