Commit 9a0e2081 authored by Michael Niedermayer's avatar Michael Niedermayer

avcodec/util: Make size argument of ff_alloc_packet2() int64_t

This ensures that huge sizes dont get truncated before the check in ff_alloc_packet2()
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent a5615b82
...@@ -171,7 +171,7 @@ int avpriv_unlock_avformat(void); ...@@ -171,7 +171,7 @@ int avpriv_unlock_avformat(void);
* @param size the minimum required packet size * @param size the minimum required packet size
* @return 0 on success, negative error code on failure * @return 0 on success, negative error code on failure
*/ */
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int size); int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size);
int ff_alloc_packet(AVPacket *avpkt, int size); int ff_alloc_packet(AVPacket *avpkt, int size);
......
...@@ -1425,14 +1425,14 @@ free_and_end: ...@@ -1425,14 +1425,14 @@ free_and_end:
goto end; goto end;
} }
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int size) int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
{ {
if (avpkt->size < 0) { if (avpkt->size < 0) {
av_log(avctx, AV_LOG_ERROR, "Invalid negative user packet size %d\n", avpkt->size); av_log(avctx, AV_LOG_ERROR, "Invalid negative user packet size %d\n", avpkt->size);
return AVERROR(EINVAL); return AVERROR(EINVAL);
} }
if (size < 0 || size > INT_MAX - FF_INPUT_BUFFER_PADDING_SIZE) { if (size < 0 || size > INT_MAX - FF_INPUT_BUFFER_PADDING_SIZE) {
av_log(avctx, AV_LOG_ERROR, "Invalid minimum required packet size %d (max allowed is %d)\n", av_log(avctx, AV_LOG_ERROR, "Invalid minimum required packet size %"PRId64" (max allowed is %d)\n",
size, INT_MAX - FF_INPUT_BUFFER_PADDING_SIZE); size, INT_MAX - FF_INPUT_BUFFER_PADDING_SIZE);
return AVERROR(EINVAL); return AVERROR(EINVAL);
} }
...@@ -1456,7 +1456,7 @@ FF_ENABLE_DEPRECATION_WARNINGS ...@@ -1456,7 +1456,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
#endif #endif
if (avpkt->size < size) { if (avpkt->size < size) {
av_log(avctx, AV_LOG_ERROR, "User packet is too small (%d < %d)\n", avpkt->size, size); av_log(avctx, AV_LOG_ERROR, "User packet is too small (%d < %"PRId64")\n", avpkt->size, size);
return AVERROR(EINVAL); return AVERROR(EINVAL);
} }
...@@ -1472,7 +1472,7 @@ FF_ENABLE_DEPRECATION_WARNINGS ...@@ -1472,7 +1472,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
} else { } else {
int ret = av_new_packet(avpkt, size); int ret = av_new_packet(avpkt, size);
if (ret < 0) if (ret < 0)
av_log(avctx, AV_LOG_ERROR, "Failed to allocate packet of size %d\n", size); av_log(avctx, AV_LOG_ERROR, "Failed to allocate packet of size %"PRId64"\n", size);
return ret; return ret;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment