]> git.sesse.net Git - ffmpeg/commit
avformat/matroskaenc: Check allocations implicit in dynamic buffers
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Wed, 29 Apr 2020 18:55:26 +0000 (20:55 +0200)
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Wed, 6 May 2020 08:49:51 +0000 (10:49 +0200)
commit3a822717bd6b0dd88ad8676ed9133dd65f7dd56a
tree623ec8100edc3ca04748913e5fe06bd54e286cc7
parent8370c9c206367acaec1130fe47582590123b1b64
avformat/matroskaenc: Check allocations implicit in dynamic buffers

Failures of the allocations that happen under the hood when using dynamic
buffers are usually completely unchecked and the Matroska muxer is no
exception to this.

The API has its part in this, because there is no documented way to
actually check for errors: The return value of both avio_get_dyn_buf()
as well as avio_close_dyn_buf() is only documented as "the length of
the byte buffer", so that using this to return errors would be an API
break.

Therefore this commit uses the only reliable way to check for errors
with avio_get_dyn_buf(): The AVIOContext's error flag. (This is one of
the advantages of avio_get_dyn_buf(): By not destroying the AVIOContext
it is possible to inspect this value.) Checking whether the size or the
pointer vanishes is not enough as it does not check for truncated output
(the dynamic buffer API is int based and so has to truncate the buffer
even when enough memory would be available; it's current actual limit is
even way below INT_MAX).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
libavformat/matroskaenc.c