[FFmpeg-cvslog] rtmp: fix buffer overflows in ff_amf_tag_contents()
Xi Wang
git at videolan.org
Thu Feb 14 14:19:37 CET 2013
ffmpeg | branch: release/0.8 | Xi Wang <xi.wang at gmail.com> | Tue Jan 22 21:40:05 2013 -0500| [b59ee5dcf119f900a3e9f45098f9e992a5f26fd0] | committer: Michael Niedermayer
rtmp: fix buffer overflows in ff_amf_tag_contents()
A negative `size' will bypass FFMIN(). In the subsequent memcpy() call,
`size' will be considered as a large positive value, leading to a buffer
overflow.
Change the type of `size' to unsigned int to avoid buffer overflow, and
simplify overflow checks accordingly.
Signed-off-by: Xi Wang <xi.wang at gmail.com>
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
(cherry picked from commit 4e692374f7962ea358c329de38c380103f8991b6)
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b59ee5dcf119f900a3e9f45098f9e992a5f26fd0
---
libavformat/rtmppkt.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/libavformat/rtmppkt.c b/libavformat/rtmppkt.c
index 5e75e3b..c65cfc1 100644
--- a/libavformat/rtmppkt.c
+++ b/libavformat/rtmppkt.c
@@ -362,7 +362,7 @@ static const char* rtmp_packet_type(int type)
static void ff_amf_tag_contents(void *ctx, const uint8_t *data, const uint8_t *data_end)
{
- int size;
+ unsigned int size;
char buf[1024];
if (data >= data_end)
@@ -381,7 +381,7 @@ static void ff_amf_tag_contents(void *ctx, const uint8_t *data, const uint8_t *d
} else {
size = bytestream_get_be32(&data);
}
- size = FFMIN(size, 1023);
+ size = FFMIN(size, sizeof(buf) - 1);
memcpy(buf, data, size);
buf[size] = 0;
av_log(ctx, AV_LOG_DEBUG, " string '%s'\n", buf);
@@ -394,16 +394,15 @@ static void ff_amf_tag_contents(void *ctx, const uint8_t *data, const uint8_t *d
case AMF_DATA_TYPE_OBJECT:
av_log(ctx, AV_LOG_DEBUG, " {\n");
for (;;) {
- int size = bytestream_get_be16(&data);
int t;
- memcpy(buf, data, size);
- buf[size] = 0;
+ size = bytestream_get_be16(&data);
+ av_strlcpy(buf, data, FFMIN(sizeof(buf), size + 1));
if (!size) {
av_log(ctx, AV_LOG_DEBUG, " }\n");
data++;
break;
}
- if (size < 0 || size >= data_end - data)
+ if (size >= data_end - data)
return;
data += size;
av_log(ctx, AV_LOG_DEBUG, " %s: ", buf);
More information about the ffmpeg-cvslog
mailing list