mirror of https://github.com/mpv-player/mpv
packet: fix theoretical UB if called on "empty" packets
In theory, a 0 size allocation could have made it memset() on a NULL pointer (with a non-0 size, which makes it crash in addition to theoretical UB). This should never happen, since even packets with size 0 should have an associated allocation, as FFmpeg currently does. But avoiding this makes the API slightly more orthogonal and less tricky, I guess.
This commit is contained in:
parent
9a7a6958ca
commit
389f1b0ef3
|
@ -124,8 +124,10 @@ struct demux_packet *new_demux_packet(size_t len)
|
|||
void demux_packet_shorten(struct demux_packet *dp, size_t len)
|
||||
{
|
||||
assert(len <= dp->len);
|
||||
dp->len = len;
|
||||
memset(dp->buffer + dp->len, 0, AV_INPUT_BUFFER_PADDING_SIZE);
|
||||
if (dp->len) {
|
||||
dp->len = len;
|
||||
memset(dp->buffer + dp->len, 0, AV_INPUT_BUFFER_PADDING_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
void free_demux_packet(struct demux_packet *dp)
|
||||
|
|
Loading…
Reference in New Issue