On Sat, 27 Apr 2013 17:06:50 +0200, Luca Barbato <[email protected]> wrote:
> ---
> 
> Now with seek setting err properly and not wiping the iv when
> everything is fine.
> 
>  libavformat/omadec.c | 32 ++++++++++++++++++--------------
>  1 file changed, 18 insertions(+), 14 deletions(-)
> 
> diff --git a/libavformat/omadec.c b/libavformat/omadec.c
> index b932ec3..99e4bff 100644
> --- a/libavformat/omadec.c
> +++ b/libavformat/omadec.c
> @@ -200,13 +200,13 @@ static int decrypt_init(AVFormatContext *s, 
> ID3v2ExtraMeta *em, uint8_t *header)
>      }
>      if (!em) {
>          av_log(s, AV_LOG_ERROR, "No encryption header found\n");
> -        return -1;
> +        return AVERROR_INVALIDDATA;
>      }
> 
>      if (geob->datasize < 64) {
>          av_log(s, AV_LOG_ERROR,
>                 "Invalid GEOB data size: %u\n", geob->datasize);
> -        return -1;
> +        return AVERROR_INVALIDDATA;
>      }
> 
>      gdata = geob->data;
> @@ -221,7 +221,7 @@ static int decrypt_init(AVFormatContext *s, 
> ID3v2ExtraMeta *em, uint8_t *header)
> 
>      if (memcmp(&gdata[OMA_ENC_HEADER_SIZE], "KEYRING     ", 12)) {
>          av_log(s, AV_LOG_ERROR, "Invalid encryption header\n");
> -        return -1;
> +        return AVERROR_INVALIDDATA;
>      }
>      oc->rid = AV_RB32(&gdata[OMA_ENC_HEADER_SIZE + 28]);
>      av_log(s, AV_LOG_DEBUG, "RID: %.8x\n", oc->rid);
> @@ -251,7 +251,7 @@ static int decrypt_init(AVFormatContext *s, 
> ID3v2ExtraMeta *em, uint8_t *header)
>          }
>          if (i >= sizeof(leaf_table)) {
>              av_log(s, AV_LOG_ERROR, "Invalid key\n");
> -            return -1;
> +            return AVERROR_INVALIDDATA;
>          }
>      }
> 
> @@ -286,7 +286,7 @@ static int oma_read_header(AVFormatContext *s)
>      if (memcmp(buf, ((const uint8_t[]){'E', 'A', '3'}), 3) ||
>          buf[4] != 0 || buf[5] != EA3_HEADER_SIZE) {
>          av_log(s, AV_LOG_ERROR, "Couldn't find the EA3 header !\n");
> -        return -1;
> +        return AVERROR_INVALIDDATA;
>      }
> 
>      oc->content_start = avio_tell(s->pb);
> @@ -380,7 +380,7 @@ static int oma_read_header(AVFormatContext *s)
>          break;
>      default:
>          av_log(s, AV_LOG_ERROR, "Unsupported codec %d!\n", buf[32]);
> -        return -1;
> +        return AVERROR(ENOSYS);
>      }
> 
>      st->codec->block_align = framesize;
> @@ -442,24 +442,28 @@ static int oma_read_seek(struct AVFormatContext *s,
>                           int stream_index, int64_t timestamp, int flags)
>  {
>      OMAContext *oc = s->priv_data;
> -
> -    ff_pcm_read_seek(s, stream_index, timestamp, flags);
> +    int err = ff_pcm_read_seek(s, stream_index, timestamp, flags);
> 
>      if (oc->encrypted) {
>          /* readjust IV for CBC */
>          int64_t pos = avio_tell(s->pb);
> -        if (pos < oc->content_start)
> +        if (err || pos < oc->content_start)
>              memset(oc->iv, 0, 8);
>          else {
> -            if (avio_seek(s->pb, -8, SEEK_CUR) < 0 ||
> -                avio_read(s->pb, oc->iv, 8) < 8) {
> -                memset(oc->iv, 0, 8);
> -                return -1;
> +            if ((err = avio_seek(s->pb, -8, SEEK_CUR)) >= 0) {
> +                if ((err = avio_read(s->pb, oc->iv, 8)) > 0) {
> +                    if (err < 8)
> +                        err = AVERROR_EOF;
> +                    else
> +                        err = 0;
> +                }
>              }

This is starting to look messy.
I think adding a goto fail with
fail:
    if (err < 0)
        memset(oc->iv, 0, sizeof(oc->iv));
right before return err; would make this much clearer.

-- 
Anton Khirnov
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to