| @@ -210,7 +210,7 @@ static int get_video_buffer(AVFrame *frame, int align) · 209 unmodified lines |
| 210 | padded_height, linesizes)) < 0) | 210 | padded_height, linesizes)) < 0) |
| 211 | return ret; | 211 | return ret; |
| 212 | | 212 | |
| 213 | total_size = 4*plane_padding; | 213 | total_size = 4 * plane_padding + 4 * align; |
| 214 | for (int i = 0; i < 4; i++) { | 214 | for (int i = 0; i < 4; i++) { |
| 215 | if (sizes[i] > SIZE_MAX - total_size) | 215 | if (sizes[i] > SIZE_MAX - total_size) |
| 216 | return AVERROR(EINVAL); | 216 | return AVERROR(EINVAL); |
| @@ -230,6 +230,7 @@ static int get_video_buffer(AVFrame *frame, int align) · 13 unmodified lines |
| 230 | for (int i = 1; i < 4; i++) { | 230 | for (int i = 1; i < 4; i++) { |
| 231 | if (frame->data[i]) | 231 | if (frame->data[i]) |
| 232 | frame->data[i] += i * plane_padding; | 232 | frame->data[i] += i * plane_padding; |
| | 233 | frame->data[i] = (uint8_t *)FFALIGN((uintptr_t)frame->data[i], align); |
| 233 | } | 234 | } |
| 234 | | 235 | |
| 235 | frame->extended_data = frame->data; | 236 | frame->extended_data = frame->data; |
| @@ -244,6 +245,7 @@ static int get_audio_buffer(AVFrame *frame, int align) · 8 unmodified lines |
| 244 | { | 245 | { |
| 245 | int planar = av_sample_fmt_is_planar(frame->format); | 246 | int planar = av_sample_fmt_is_planar(frame->format); |
| 246 | int channels, planes; | 247 | int channels, planes; |
| | 248 | size_t size; |
| 247 | int ret; | 249 | int ret; |
| 248 | | 250 | |
| 249 | channels = frame->ch_layout.nb_channels; | 251 | channels = frame->ch_layout.nb_channels; |
| @@ -256,6 +258,9 @@ static int get_audio_buffer(AVFrame *frame, int align) · 6 unmodified lines |
| 256 | return ret; | 258 | return ret; |
| 257 | } | 259 | } |
| 258 | | 260 | |
| | 261 | if (align <= 0) |
| | 262 | align = ALIGN; |
| | 263 | |
| 259 | if (planes > AV_NUM_DATA_POINTERS) { | 264 | if (planes > AV_NUM_DATA_POINTERS) { |
| 260 | frame->extended_data = av_calloc(planes, | 265 | frame->extended_data = av_calloc(planes, |
| 261 | sizeof(*frame->extended_data)); | 266 | sizeof(*frame->extended_data)); |
| @@ -270,21 +275,27 @@ static int get_audio_buffer(AVFrame *frame, int align) · 8 unmodified lines |
| 270 | } else | 275 | } else |
| 271 | frame->extended_data = frame->data; | 276 | frame->extended_data = frame->data; |
| 272 | | 277 | |
| | 278 | if (frame->linesize[0] > SIZE_MAX - align) |
| | 279 | return AVERROR(EINVAL); |
| | 280 | size = frame->linesize[0] + (size_t)align; |
| | 281 | |
| 273 | for (int i = 0; i < FFMIN(planes, AV_NUM_DATA_POINTERS); i++) { | 282 | for (int i = 0; i < FFMIN(planes, AV_NUM_DATA_POINTERS); i++) { |
| 274 | frame->buf[i] = av_buffer_alloc(frame->linesize[0]); | 283 | frame->buf[i] = av_buffer_alloc(size); |
| 275 | if (!frame->buf[i]) { | 284 | if (!frame->buf[i]) { |
| 276 | av_frame_unref(frame); | 285 | av_frame_unref(frame); |
| 277 | return AVERROR(ENOMEM); | 286 | return AVERROR(ENOMEM); |
| 278 | } | 287 | } |
| 279 | frame->extended_data[i] = frame->data[i] = frame->buf[i]->data; | 288 | frame->extended_data[i] = frame->data[i] = |
| | 289 | (uint8_t *)FFALIGN((uintptr_t)frame->buf[i]->data, align); |
| 280 | } | 290 | } |
| 281 | for (int i = 0; i < planes - AV_NUM_DATA_POINTERS; i++) { | 291 | for (int i = 0; i < planes - AV_NUM_DATA_POINTERS; i++) { |
| 282 | frame->extended_buf[i] = av_buffer_alloc(frame->linesize[0]); | 292 | frame->extended_buf[i] = av_buffer_alloc(size); |
| 283 | if (!frame->extended_buf[i]) { | 293 | if (!frame->extended_buf[i]) { |
| 284 | av_frame_unref(frame); | 294 | av_frame_unref(frame); |
| 285 | return AVERROR(ENOMEM); | 295 | return AVERROR(ENOMEM); |
| 286 | } | 296 | } |
| 287 | frame->extended_data[i + AV_NUM_DATA_POINTERS] = frame->extended_buf[i]->data; | 297 | frame->extended_data[i + AV_NUM_DATA_POINTERS] = |
| | 298 | (uint8_t *)FFALIGN((uintptr_t)frame->extended_buf[i]->data, align); |
| 288 | } | 299 | } |
| 289 | return 0; | 300 | return 0; |
| 290 | | 301 | |