mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2024-12-22 15:23:11 +00: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:
parent
e95fdf7660
commit
63b3156558
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user