diff mbox series

[FFmpeg-devel,4/5] avformat/aviobuf: Return better error codes

Message ID 20200525140801.18889-4-andreas.rheinhardt@gmail.com
State Accepted
Commit 7be9b0bb38f415d06d06a10844d181b0a8421c47
Headers show
Series [FFmpeg-devel,1/5] avformat/aviobuf: Don't check for overflow after it happened
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Andreas Rheinhardt May 25, 2020, 2:08 p.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavformat/aviobuf.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

Comments

Michael Niedermayer May 25, 2020, 4:04 p.m. UTC | #1
On Mon, May 25, 2020 at 04:08:00PM +0200, Andreas Rheinhardt wrote:
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavformat/aviobuf.c | 14 ++++++++------
>  1 file changed, 8 insertions(+), 6 deletions(-)

probably ok

thx

[...]
diff mbox series

Patch

diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 688c7c50fd..a13c677875 100644
--- a/libavformat/aviobuf.c
+++ b/libavformat/aviobuf.c
@@ -696,7 +696,7 @@  int avio_read_partial(AVIOContext *s, unsigned char *buf, int size)
     int len;
 
     if (size < 0)
-        return -1;
+        return AVERROR(EINVAL);
 
     if (s->read_packet && s->write_flag) {
         len = read_packet_wrapper(s, buf, size);
@@ -1277,7 +1277,7 @@  static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size)
     /* reallocate buffer if needed */
     new_size = (unsigned)d->pos + buf_size;
     if (new_size < d->pos || new_size > INT_MAX)
-        return -1;
+        return AVERROR(ERANGE);
     if (new_size > d->allocated_size) {
         unsigned new_allocated_size = d->allocated_size ? d->allocated_size
                                                         : new_size;
@@ -1324,8 +1324,10 @@  static int64_t dyn_buf_seek(void *opaque, int64_t offset, int whence)
         offset += d->pos;
     else if (whence == SEEK_END)
         offset += d->size;
-    if (offset < 0 || offset > 0x7fffffffLL)
-        return -1;
+    if (offset < 0)
+        return AVERROR(EINVAL);
+    if (offset > INT_MAX)
+        return AVERROR(ERANGE);
     d->pos = offset;
     return 0;
 }
@@ -1336,7 +1338,7 @@  static int url_open_dyn_buf_internal(AVIOContext **s, int max_packet_size)
     unsigned io_buffer_size = max_packet_size ? max_packet_size : 1024;
 
     if (sizeof(DynBuffer) + io_buffer_size < io_buffer_size)
-        return -1;
+        return AVERROR(ERANGE);
     d = av_mallocz(sizeof(DynBuffer) + io_buffer_size);
     if (!d)
         return AVERROR(ENOMEM);
@@ -1360,7 +1362,7 @@  int avio_open_dyn_buf(AVIOContext **s)
 int ffio_open_dyn_packet_buf(AVIOContext **s, int max_packet_size)
 {
     if (max_packet_size <= 0)
-        return -1;
+        return AVERROR(EINVAL);
     return url_open_dyn_buf_internal(s, max_packet_size);
 }