[FFmpeg-cvslog] avformat/aviobuf: Also return truncated buffer in avio_get_dyn_buf()

Andreas Rheinhardt git at videolan.org
Wed Jul 1 20:15:51 EEST 2020


ffmpeg | branch: release/4.3 | Andreas Rheinhardt <andreas.rheinhardt at gmail.com> | Mon May 25 10:14:00 2020 +0200| [d8407afe021c525c25b6b39ae2d8dc3b6dbde6fe] | committer: Andreas Rheinhardt

avformat/aviobuf: Also return truncated buffer in avio_get_dyn_buf()

Two kinds of errors can happen when working with dynamic buffers:
(Re)allocation errors or truncation errors (one has to truncate the
buffer to a size of INT_MAX because avio_close_dyn_buf() and
avio_get_dyn_buf() both return an int). Right now, avio_get_dyn_buf()
returns an empty buffer in either case. But given that
avio_get_dyn_buf() does not destroy the dynamic buffer, one can return
the buffer in case of truncation and let the user check the error flags
and decide for himself instead of hardcoding a single way to proceed
in case of truncation.

(This actually restores the behaviour from before commit
163bb9ac0af495a5cb95441bdb5c02170440d28c.)

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
(cherry picked from commit c33e56c7a6a8bef7d95e1d36eb2f35748d475695)
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d8407afe021c525c25b6b39ae2d8dc3b6dbde6fe
---

 libavformat/aviobuf.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 33c2d6f037..a48ceebaef 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -1369,13 +1369,13 @@ int avio_get_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
 {
     DynBuffer *d;
 
-    if (!s || s->error) {
+    if (!s) {
         *pbuffer = NULL;
         return 0;
     }
     d = s->opaque;
 
-    if (!d->size) {
+    if (!s->error && !d->size) {
         *pbuffer = d->io_buffer;
         return FFMAX(s->buf_ptr, s->buf_ptr_max) - s->buffer;
     }



More information about the ffmpeg-cvslog mailing list