Fixes invalid writes on pixel format changes.
Unified · Split
| @@ -52,6 +52,7 @@ typedef struct LagarithContext { · 51 unmodified lines | ||
| 52 | 52 | int zeros; /**< number of consecutive zero bytes encountered */ |
| 53 | 53 | int zeros_rem; /**< number of zero bytes remaining to output */ |
| 54 | 54 | uint8_t *rgb_planes; |
| 55 | + int rgb_planes_allocated; | |
| 55 | 56 | int rgb_stride; |
| 56 | 57 | } LagarithContext; |
| 57 | 58 | |
| @@ -564,13 +565,12 @@ static int lag_decode_frame(AVCodecContext *avctx, · 506 unmodified lines | ||
| 564 | 565 | offs[1] = offset_gu; |
| 565 | 566 | offs[2] = offset_ry; |
| 566 | 567 | |
| 568 | + l->rgb_stride = FFALIGN(avctx->width, 16); | |
| 569 | + av_fast_malloc(&l->rgb_planes, &l->rgb_planes_allocated, | |
| 570 | + l->rgb_stride * avctx->height * planes + 1); | |
| 567 | 571 | if (!l->rgb_planes) { |
| 568 | − l->rgb_stride = FFALIGN(avctx->width, 16); | |
| 569 | − l->rgb_planes = av_malloc(l->rgb_stride * avctx->height * planes + 1); | |
| 570 | − if (!l->rgb_planes) { | |
| 571 | − av_log(avctx, AV_LOG_ERROR, "cannot allocate temporary buffer\n"); | |
| 572 | − return AVERROR(ENOMEM); | |
| 573 | − } | |
| 572 | + av_log(avctx, AV_LOG_ERROR, "cannot allocate temporary buffer\n"); | |
| 573 | + return AVERROR(ENOMEM); | |
| 574 | 574 | } |
| 575 | 575 | for (i = 0; i < planes; i++) |
| 576 | 576 | srcs[i] = l->rgb_planes + (i + 1) * l->rgb_stride * avctx->height - l->rgb_stride; |