Message ID | 20210211154227.114-1-jamrial@gmail.com |
---|---|
State | Accepted |
Commit | 22edf7463c4d6d2dfe9c8673d163120a8a50911a |
Headers | show |
Series | [FFmpeg-devel] avcodec/hevcdec: add some missing allocation checks | expand |
Context | Check | Description |
---|---|---|
andriy/x86_make | success | Make finished |
andriy/x86_make_fate | success | Make fate finished |
andriy/PPC64_make | success | Make finished |
andriy/PPC64_make_fate | success | Make fate finished |
probably ok
On 2/11/2021 12:57 PM, Paul B Mahol wrote:
> probably ok
Applied. Thanks.
On Thu, Feb 11, 2021 at 11:49 PM James Almer <jamrial@gmail.com> wrote: > Signed-off-by: James Almer <jamrial@gmail.com> > --- > libavcodec/hevcdec.c | 25 +++++++++++++++++++------ > 1 file changed, 19 insertions(+), 6 deletions(-) > > diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c > index 898dac8cbb..325c7850e6 100644 > --- a/libavcodec/hevcdec.c > +++ b/libavcodec/hevcdec.c > @@ -515,6 +515,9 @@ static int set_sps(HEVCContext *s, const HEVCSPS *sps, > s->sao_pixel_buffer_v[c_idx] = > av_malloc((h * 2 * sps->ctb_width) << > sps->pixel_shift); > + if (!s->sao_pixel_buffer_h[c_idx] || > + !s->sao_pixel_buffer_v[c_idx]) > + goto fail; > } > } > > @@ -525,6 +528,10 @@ static int set_sps(HEVCContext *s, const HEVCSPS *sps, > > fail: > pic_arrays_free(s); > + for (i = 0; i < 3; i++) { > + av_freep(&s->sao_pixel_buffer_h[i]); > + av_freep(&s->sao_pixel_buffer_v[i]); > + } > We have the same code after ff_videodsp_init and the same code in hevc_decode_free. Could we define a function like free_sao_pixel_buffers for it? > s->ps.sps = NULL; > return ret; > } > @@ -2624,13 +2631,19 @@ static int hls_slice_data_wpp(HEVCContext *s, > const H2645NAL *nal) > > ff_alloc_entries(s->avctx, s->sh.num_entry_point_offsets + 1); > > - if (!s->sList[1]) { > - for (i = 1; i < s->threads_number; i++) { > - s->sList[i] = av_malloc(sizeof(HEVCContext)); > - memcpy(s->sList[i], s, sizeof(HEVCContext)); > - s->HEVClcList[i] = av_mallocz(sizeof(HEVCLocalContext)); > - s->sList[i]->HEVClc = s->HEVClcList[i]; > + for (i = 1; i < s->threads_number; i++) { > + if (s->sList[i] && s->HEVClcList[i]) > + continue; > + av_freep(&s->sList[i]); > + av_freep(&s->HEVClcList[i]); > + s->sList[i] = av_malloc(sizeof(HEVCContext)); > + s->HEVClcList[i] = av_mallocz(sizeof(HEVCLocalContext)); > + if (!s->sList[i] || !s->HEVClcList[i]) { > + res = AVERROR_INVALIDDATA; > AVERROR(ENOMEM) ? > + goto error; > } > + memcpy(s->sList[i], s, sizeof(HEVCContext)); > + s->sList[i]->HEVClc = s->HEVClcList[i]; > } > > offset = (lc->gb.index >> 3); > -- > 2.30.0 > > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c index 898dac8cbb..325c7850e6 100644 --- a/libavcodec/hevcdec.c +++ b/libavcodec/hevcdec.c @@ -515,6 +515,9 @@ static int set_sps(HEVCContext *s, const HEVCSPS *sps, s->sao_pixel_buffer_v[c_idx] = av_malloc((h * 2 * sps->ctb_width) << sps->pixel_shift); + if (!s->sao_pixel_buffer_h[c_idx] || + !s->sao_pixel_buffer_v[c_idx]) + goto fail; } } @@ -525,6 +528,10 @@ static int set_sps(HEVCContext *s, const HEVCSPS *sps, fail: pic_arrays_free(s); + for (i = 0; i < 3; i++) { + av_freep(&s->sao_pixel_buffer_h[i]); + av_freep(&s->sao_pixel_buffer_v[i]); + } s->ps.sps = NULL; return ret; } @@ -2624,13 +2631,19 @@ static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal) ff_alloc_entries(s->avctx, s->sh.num_entry_point_offsets + 1); - if (!s->sList[1]) { - for (i = 1; i < s->threads_number; i++) { - s->sList[i] = av_malloc(sizeof(HEVCContext)); - memcpy(s->sList[i], s, sizeof(HEVCContext)); - s->HEVClcList[i] = av_mallocz(sizeof(HEVCLocalContext)); - s->sList[i]->HEVClc = s->HEVClcList[i]; + for (i = 1; i < s->threads_number; i++) { + if (s->sList[i] && s->HEVClcList[i]) + continue; + av_freep(&s->sList[i]); + av_freep(&s->HEVClcList[i]); + s->sList[i] = av_malloc(sizeof(HEVCContext)); + s->HEVClcList[i] = av_mallocz(sizeof(HEVCLocalContext)); + if (!s->sList[i] || !s->HEVClcList[i]) { + res = AVERROR_INVALIDDATA; + goto error; } + memcpy(s->sList[i], s, sizeof(HEVCContext)); + s->sList[i]->HEVClc = s->HEVClcList[i]; } offset = (lc->gb.index >> 3);
Signed-off-by: James Almer <jamrial@gmail.com> --- libavcodec/hevcdec.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-)