mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2024-12-17 21:14:47 +00:00
matroskadec: simplify/cleanup error logging in ebml_read_*()
Originally committed as revision 14589 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
54d8869d3a
commit
ba5a1f99cc
@ -630,13 +630,8 @@ ebml_read_uint (MatroskaDemuxContext *matroska,
|
|||||||
(res = ebml_read_element_length(matroska, &rlength)) < 0)
|
(res = ebml_read_element_length(matroska, &rlength)) < 0)
|
||||||
return res;
|
return res;
|
||||||
size = rlength;
|
size = rlength;
|
||||||
if (size < 1 || size > 8) {
|
if (size < 1 || size > 8)
|
||||||
offset_t pos = url_ftell(pb);
|
|
||||||
av_log(matroska->ctx, AV_LOG_ERROR,
|
|
||||||
"Invalid uint element size %d at position %"PRId64" (0x%"PRIx64")\n",
|
|
||||||
size, pos, pos);
|
|
||||||
return AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
}
|
|
||||||
|
|
||||||
/* big-endian ordening; build up number */
|
/* big-endian ordening; build up number */
|
||||||
*num = 0;
|
*num = 0;
|
||||||
@ -668,13 +663,8 @@ ebml_read_float (MatroskaDemuxContext *matroska,
|
|||||||
*num= av_int2flt(get_be32(pb));
|
*num= av_int2flt(get_be32(pb));
|
||||||
} else if(size==8){
|
} else if(size==8){
|
||||||
*num= av_int2dbl(get_be64(pb));
|
*num= av_int2dbl(get_be64(pb));
|
||||||
} else{
|
} else
|
||||||
offset_t pos = url_ftell(pb);
|
|
||||||
av_log(matroska->ctx, AV_LOG_ERROR,
|
|
||||||
"Invalid float element size %d at position %"PRIu64" (0x%"PRIx64")\n",
|
|
||||||
size, pos, pos);
|
|
||||||
return AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -699,14 +689,9 @@ ebml_read_ascii (MatroskaDemuxContext *matroska,
|
|||||||
|
|
||||||
/* ebml strings are usually not 0-terminated, so we allocate one
|
/* ebml strings are usually not 0-terminated, so we allocate one
|
||||||
* byte more, read the string and NULL-terminate it ourselves. */
|
* byte more, read the string and NULL-terminate it ourselves. */
|
||||||
if (size < 0 || !(*str = av_malloc(size + 1))) {
|
if (size < 0 || !(*str = av_malloc(size + 1)))
|
||||||
av_log(matroska->ctx, AV_LOG_ERROR, "Memory allocation failed\n");
|
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
}
|
|
||||||
if (get_buffer(pb, (uint8_t *) *str, size) != size) {
|
if (get_buffer(pb, (uint8_t *) *str, size) != size) {
|
||||||
offset_t pos = url_ftell(pb);
|
|
||||||
av_log(matroska->ctx, AV_LOG_ERROR,
|
|
||||||
"Read error at pos. %"PRIu64" (0x%"PRIx64")\n", pos, pos);
|
|
||||||
av_free(*str);
|
av_free(*str);
|
||||||
return AVERROR(EIO);
|
return AVERROR(EIO);
|
||||||
}
|
}
|
||||||
@ -765,18 +750,11 @@ ebml_read_binary (MatroskaDemuxContext *matroska,
|
|||||||
return res;
|
return res;
|
||||||
*size = rlength;
|
*size = rlength;
|
||||||
|
|
||||||
if (!(*binary = av_malloc(*size))) {
|
if (!(*binary = av_malloc(*size)))
|
||||||
av_log(matroska->ctx, AV_LOG_ERROR,
|
|
||||||
"Memory allocation error\n");
|
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
}
|
|
||||||
|
|
||||||
if (get_buffer(pb, *binary, *size) != *size) {
|
if (get_buffer(pb, *binary, *size) != *size)
|
||||||
offset_t pos = url_ftell(pb);
|
|
||||||
av_log(matroska->ctx, AV_LOG_ERROR,
|
|
||||||
"Read error at pos. %"PRIu64" (0x%"PRIx64")\n", pos, pos);
|
|
||||||
return AVERROR(EIO);
|
return AVERROR(EIO);
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -988,15 +966,15 @@ static int ebml_parse_elem(MatroskaDemuxContext *matroska,
|
|||||||
bin = data;
|
bin = data;
|
||||||
|
|
||||||
switch (syntax->type) {
|
switch (syntax->type) {
|
||||||
case EBML_UINT: return ebml_read_uint (matroska, &id, data);
|
case EBML_UINT: res = ebml_read_uint (matroska, &id, data); break;
|
||||||
case EBML_FLOAT: return ebml_read_float(matroska, &id, data);
|
case EBML_FLOAT: res = ebml_read_float(matroska, &id, data); break;
|
||||||
case EBML_STR:
|
case EBML_STR:
|
||||||
case EBML_UTF8: av_free(*(char **)data);
|
case EBML_UTF8: av_free(*(char **)data);
|
||||||
return ebml_read_ascii(matroska, &id, data);
|
res = ebml_read_ascii(matroska, &id, data); break;
|
||||||
case EBML_BIN: av_free(bin->data);
|
case EBML_BIN: av_free(bin->data);
|
||||||
bin->pos = url_ftell(matroska->ctx->pb);
|
bin->pos = url_ftell(matroska->ctx->pb);
|
||||||
return ebml_read_binary(matroska, &id, &bin->data,
|
res = ebml_read_binary(matroska, &id, &bin->data,
|
||||||
&bin->size);
|
&bin->size); break;
|
||||||
case EBML_NEST: if ((res=ebml_read_master(matroska, &id)) < 0)
|
case EBML_NEST: if ((res=ebml_read_master(matroska, &id)) < 0)
|
||||||
return res;
|
return res;
|
||||||
if (id == MATROSKA_ID_SEGMENT)
|
if (id == MATROSKA_ID_SEGMENT)
|
||||||
@ -1006,6 +984,11 @@ static int ebml_parse_elem(MatroskaDemuxContext *matroska,
|
|||||||
case EBML_STOP: *(int *)data = 1; return 1;
|
case EBML_STOP: *(int *)data = 1; return 1;
|
||||||
default: return ebml_read_skip(matroska);
|
default: return ebml_read_skip(matroska);
|
||||||
}
|
}
|
||||||
|
if (res == AVERROR_INVALIDDATA)
|
||||||
|
av_log(matroska->ctx, AV_LOG_ERROR, "Invalid element\n");
|
||||||
|
else if (res == AVERROR(EIO))
|
||||||
|
av_log(matroska->ctx, AV_LOG_ERROR, "Read error\n");
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ebml_parse_id(MatroskaDemuxContext *matroska, EbmlSyntax *syntax,
|
static int ebml_parse_id(MatroskaDemuxContext *matroska, EbmlSyntax *syntax,
|
||||||
|
Loading…
Reference in New Issue
Block a user