[FFmpeg-devel] [PATCH] lavu/imgutils: add consistency check to av_image_copy_plane()
Stefano Sabatini
stefasab at gmail.com
Sat Sep 8 00:35:50 CEST 2012
Add assertions and abort in case of invalid |dst_linesize| < bytewidth or
|src_linesize| < bytewidth.
Avoid to silently corrupt memory.
TODO: bump micro
---
libavutil/imgutils.c | 3 +++
libavutil/imgutils.h | 3 +++
2 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/libavutil/imgutils.c b/libavutil/imgutils.c
index a3d4087..20df7b1 100644
--- a/libavutil/imgutils.c
+++ b/libavutil/imgutils.c
@@ -21,6 +21,7 @@
* misc image utilities
*/
+#include "avassert.h"
#include "common.h"
#include "imgutils.h"
#include "internal.h"
@@ -235,6 +236,8 @@ void av_image_copy_plane(uint8_t *dst, int dst_linesize,
const uint8_t *src, int src_linesize,
int bytewidth, int height)
{
+ av_assert0(abs(src_linesize) >= bytewidth);
+ av_assert0(abs(dst_linesize) >= bytewidth);
if (!dst || !src)
return;
for (;height > 0; height--) {
diff --git a/libavutil/imgutils.h b/libavutil/imgutils.h
index 3b1904b..1434dbd 100644
--- a/libavutil/imgutils.h
+++ b/libavutil/imgutils.h
@@ -99,6 +99,9 @@ int av_image_alloc(uint8_t *pointers[4], int linesizes[4],
* The first byte of each successive line is separated by *_linesize
* bytes.
*
+ * bytewidth must be contained by both absolute values of dst_linesize
+ * and src_linesize, otherwise the function behavior is undefined.
+ *
* @param dst_linesize linesize for the image plane in dst
* @param src_linesize linesize for the image plane in src
*/
--
1.7.5.4
More information about the ffmpeg-devel
mailing list