Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.wasm-core
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ffmpeg.wasm-core
Commits
53df079a
Commit
53df079a
authored
Oct 06, 2011
by
Justin Ruggles
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
alacdec: check for buffer allocation failure.
Also rearranges some functions for easier cleanup on failure.
parent
e5e4f92b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
57 deletions
+69
-57
alac.c
libavcodec/alac.c
+69
-57
No files found.
libavcodec/alac.c
View file @
53df079a
...
...
@@ -85,49 +85,6 @@ typedef struct {
int
wasted_bits
;
}
ALACContext
;
static
void
allocate_buffers
(
ALACContext
*
alac
)
{
int
chan
;
for
(
chan
=
0
;
chan
<
alac
->
numchannels
;
chan
++
)
{
alac
->
predicterror_buffer
[
chan
]
=
av_malloc
(
alac
->
setinfo_max_samples_per_frame
*
4
);
alac
->
outputsamples_buffer
[
chan
]
=
av_malloc
(
alac
->
setinfo_max_samples_per_frame
*
4
);
alac
->
wasted_bits_buffer
[
chan
]
=
av_malloc
(
alac
->
setinfo_max_samples_per_frame
*
4
);
}
}
static
int
alac_set_info
(
ALACContext
*
alac
)
{
const
unsigned
char
*
ptr
=
alac
->
avctx
->
extradata
;
ptr
+=
4
;
/* size */
ptr
+=
4
;
/* alac */
ptr
+=
4
;
/* 0 ? */
if
(
AV_RB32
(
ptr
)
>=
UINT_MAX
/
4
){
av_log
(
alac
->
avctx
,
AV_LOG_ERROR
,
"setinfo_max_samples_per_frame too large
\n
"
);
return
-
1
;
}
/* buffer size / 2 ? */
alac
->
setinfo_max_samples_per_frame
=
bytestream_get_be32
(
&
ptr
);
ptr
++
;
/* ??? */
alac
->
setinfo_sample_size
=
*
ptr
++
;
alac
->
setinfo_rice_historymult
=
*
ptr
++
;
alac
->
setinfo_rice_initialhistory
=
*
ptr
++
;
alac
->
setinfo_rice_kmodifier
=
*
ptr
++
;
alac
->
numchannels
=
*
ptr
++
;
bytestream_get_be16
(
&
ptr
);
/* ??? */
bytestream_get_be32
(
&
ptr
);
/* max coded frame size */
bytestream_get_be32
(
&
ptr
);
/* bitrate ? */
bytestream_get_be32
(
&
ptr
);
/* samplerate */
return
0
;
}
static
inline
int
decode_scalar
(
GetBitContext
*
gb
,
int
k
,
int
limit
,
int
readsamplesize
){
/* read x - number of 1s before 0 represent the rice */
int
x
=
get_unary_0_9
(
gb
);
...
...
@@ -627,8 +584,74 @@ static int alac_decode_frame(AVCodecContext *avctx,
return
input_buffer_size
;
}
static
av_cold
int
alac_decode_close
(
AVCodecContext
*
avctx
)
{
ALACContext
*
alac
=
avctx
->
priv_data
;
int
chan
;
for
(
chan
=
0
;
chan
<
alac
->
numchannels
;
chan
++
)
{
av_freep
(
&
alac
->
predicterror_buffer
[
chan
]);
av_freep
(
&
alac
->
outputsamples_buffer
[
chan
]);
av_freep
(
&
alac
->
wasted_bits_buffer
[
chan
]);
}
return
0
;
}
static
int
allocate_buffers
(
ALACContext
*
alac
)
{
int
chan
;
for
(
chan
=
0
;
chan
<
alac
->
numchannels
;
chan
++
)
{
alac
->
predicterror_buffer
[
chan
]
=
av_malloc
(
alac
->
setinfo_max_samples_per_frame
*
4
);
alac
->
outputsamples_buffer
[
chan
]
=
av_malloc
(
alac
->
setinfo_max_samples_per_frame
*
4
);
alac
->
wasted_bits_buffer
[
chan
]
=
av_malloc
(
alac
->
setinfo_max_samples_per_frame
*
4
);
if
(
!
alac
->
predicterror_buffer
[
chan
]
||
!
alac
->
outputsamples_buffer
[
chan
]
||
!
alac
->
wasted_bits_buffer
[
chan
])
{
alac_decode_close
(
alac
->
avctx
);
return
AVERROR
(
ENOMEM
);
}
}
return
0
;
}
static
int
alac_set_info
(
ALACContext
*
alac
)
{
const
unsigned
char
*
ptr
=
alac
->
avctx
->
extradata
;
ptr
+=
4
;
/* size */
ptr
+=
4
;
/* alac */
ptr
+=
4
;
/* 0 ? */
if
(
AV_RB32
(
ptr
)
>=
UINT_MAX
/
4
){
av_log
(
alac
->
avctx
,
AV_LOG_ERROR
,
"setinfo_max_samples_per_frame too large
\n
"
);
return
-
1
;
}
/* buffer size / 2 ? */
alac
->
setinfo_max_samples_per_frame
=
bytestream_get_be32
(
&
ptr
);
ptr
++
;
/* ??? */
alac
->
setinfo_sample_size
=
*
ptr
++
;
alac
->
setinfo_rice_historymult
=
*
ptr
++
;
alac
->
setinfo_rice_initialhistory
=
*
ptr
++
;
alac
->
setinfo_rice_kmodifier
=
*
ptr
++
;
alac
->
numchannels
=
*
ptr
++
;
bytestream_get_be16
(
&
ptr
);
/* ??? */
bytestream_get_be32
(
&
ptr
);
/* max coded frame size */
bytestream_get_be32
(
&
ptr
);
/* bitrate ? */
bytestream_get_be32
(
&
ptr
);
/* samplerate */
return
0
;
}
static
av_cold
int
alac_decode_init
(
AVCodecContext
*
avctx
)
{
int
ret
;
ALACContext
*
alac
=
avctx
->
priv_data
;
alac
->
avctx
=
avctx
;
...
...
@@ -668,20 +691,9 @@ static av_cold int alac_decode_init(AVCodecContext * avctx)
return
AVERROR_PATCHWELCOME
;
}
allocate_buffers
(
alac
);
return
0
;
}
static
av_cold
int
alac_decode_close
(
AVCodecContext
*
avctx
)
{
ALACContext
*
alac
=
avctx
->
priv_data
;
int
chan
;
for
(
chan
=
0
;
chan
<
alac
->
numchannels
;
chan
++
)
{
av_freep
(
&
alac
->
predicterror_buffer
[
chan
]);
av_freep
(
&
alac
->
outputsamples_buffer
[
chan
]);
av_freep
(
&
alac
->
wasted_bits_buffer
[
chan
]);
if
((
ret
=
allocate_buffers
(
alac
))
<
0
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"Error allocating buffers
\n
"
);
return
ret
;
}
return
0
;
...
...
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