1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

avformat/aviobuf: Don't use NULL as src for memcpy

This might happen in avio_write() if size == 0
when the direct codepath is taken. It is undefined behaviour
according to the spec although it happens to work in practice.
Fixes the webm-webvtt-remux FATE-test under UBSan.

Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2022-09-28 19:38:01 +02:00
parent e95fdf7660
commit 63b3156558

View File

@ -231,12 +231,14 @@ void ffio_fill(AVIOContext *s, int b, int64_t count)
void avio_write(AVIOContext *s, const unsigned char *buf, int size) void avio_write(AVIOContext *s, const unsigned char *buf, int size)
{ {
if (size <= 0)
return;
if (s->direct && !s->update_checksum) { if (s->direct && !s->update_checksum) {
avio_flush(s); avio_flush(s);
writeout(s, buf, size); writeout(s, buf, size);
return; return;
} }
while (size > 0) { do {
int len = FFMIN(s->buf_end - s->buf_ptr, size); int len = FFMIN(s->buf_end - s->buf_ptr, size);
memcpy(s->buf_ptr, buf, len); memcpy(s->buf_ptr, buf, len);
s->buf_ptr += len; s->buf_ptr += len;
@ -246,7 +248,7 @@ void avio_write(AVIOContext *s, const unsigned char *buf, int size)
buf += len; buf += len;
size -= len; size -= len;
} } while (size > 0);
} }
void avio_flush(AVIOContext *s) void avio_flush(AVIOContext *s)