mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-02-14 22:22:59 +02:00
avformat/aviobuf: Return better error codes
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
This commit is contained in:
parent
fa0bc627c5
commit
7be9b0bb38
@ -708,7 +708,7 @@ int avio_read_partial(AVIOContext *s, unsigned char *buf, int size)
|
|||||||
int len;
|
int len;
|
||||||
|
|
||||||
if (size < 0)
|
if (size < 0)
|
||||||
return -1;
|
return AVERROR(EINVAL);
|
||||||
|
|
||||||
if (s->read_packet && s->write_flag) {
|
if (s->read_packet && s->write_flag) {
|
||||||
len = read_packet_wrapper(s, buf, size);
|
len = read_packet_wrapper(s, buf, size);
|
||||||
@ -1289,7 +1289,7 @@ static int dyn_buf_write(void *opaque, uint8_t *buf, int buf_size)
|
|||||||
/* reallocate buffer if needed */
|
/* reallocate buffer if needed */
|
||||||
new_size = (unsigned)d->pos + buf_size;
|
new_size = (unsigned)d->pos + buf_size;
|
||||||
if (new_size < d->pos || new_size > INT_MAX)
|
if (new_size < d->pos || new_size > INT_MAX)
|
||||||
return -1;
|
return AVERROR(ERANGE);
|
||||||
if (new_size > d->allocated_size) {
|
if (new_size > d->allocated_size) {
|
||||||
unsigned new_allocated_size = d->allocated_size ? d->allocated_size
|
unsigned new_allocated_size = d->allocated_size ? d->allocated_size
|
||||||
: new_size;
|
: new_size;
|
||||||
@ -1336,8 +1336,10 @@ static int64_t dyn_buf_seek(void *opaque, int64_t offset, int whence)
|
|||||||
offset += d->pos;
|
offset += d->pos;
|
||||||
else if (whence == SEEK_END)
|
else if (whence == SEEK_END)
|
||||||
offset += d->size;
|
offset += d->size;
|
||||||
if (offset < 0 || offset > 0x7fffffffLL)
|
if (offset < 0)
|
||||||
return -1;
|
return AVERROR(EINVAL);
|
||||||
|
if (offset > INT_MAX)
|
||||||
|
return AVERROR(ERANGE);
|
||||||
d->pos = offset;
|
d->pos = offset;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1348,7 +1350,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;
|
unsigned io_buffer_size = max_packet_size ? max_packet_size : 1024;
|
||||||
|
|
||||||
if (sizeof(DynBuffer) + io_buffer_size < io_buffer_size)
|
if (sizeof(DynBuffer) + io_buffer_size < io_buffer_size)
|
||||||
return -1;
|
return AVERROR(ERANGE);
|
||||||
d = av_mallocz(sizeof(DynBuffer) + io_buffer_size);
|
d = av_mallocz(sizeof(DynBuffer) + io_buffer_size);
|
||||||
if (!d)
|
if (!d)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
@ -1372,7 +1374,7 @@ int avio_open_dyn_buf(AVIOContext **s)
|
|||||||
int ffio_open_dyn_packet_buf(AVIOContext **s, int max_packet_size)
|
int ffio_open_dyn_packet_buf(AVIOContext **s, int max_packet_size)
|
||||||
{
|
{
|
||||||
if (max_packet_size <= 0)
|
if (max_packet_size <= 0)
|
||||||
return -1;
|
return AVERROR(EINVAL);
|
||||||
return url_open_dyn_buf_internal(s, max_packet_size);
|
return url_open_dyn_buf_internal(s, max_packet_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user