From f766f3c8f31234bbf61eb6690bfe21dbfc993d70 Mon Sep 17 00:00:00 2001 From: John Koleszar <jkoleszar@google.com> Date: Thu, 10 Jun 2010 20:14:50 -0400 Subject: [PATCH] dixie: simple validation of the frame header Change-Id: Iae8c2d421eb686d652807d44d8053eaec8f72897 --- vp8/dixie/dixie.c | 46 +++++++++++++++++++++++++++++++++++++++++++ vp8/dixie/dixie.h | 16 +++++++++++++++ vp8/vp8_dixie_iface.c | 7 +++++-- 3 files changed, 67 insertions(+), 2 deletions(-) diff --git a/vp8/dixie/dixie.c b/vp8/dixie/dixie.c index 633ac6f4bb..596c23cef7 100644 --- a/vp8/dixie/dixie.c +++ b/vp8/dixie/dixie.c @@ -11,6 +11,35 @@ #include "bit_ops.h" #include "dixie.h" + +void +decode_frame(struct vp8_decoder_ctx *ctx, + const unsigned char *data, + unsigned int sz) +{ + vpx_codec_err_t res; + + if ((res = vp8_parse_frame_header(data, sz, &ctx->frame_hdr))) + vpx_internal_error(&ctx->error, res, "Failed to parse frame header"); + + if (ctx->frame_hdr.is_experimental) + vpx_internal_error(&ctx->error, VPX_CODEC_UNSUP_BITSTREAM, + "Experimental bitstreams not supported."); + + if (ctx->frame_hdr.version != 0) + vpx_internal_error(&ctx->error, VPX_CODEC_UNSUP_BITSTREAM, + "Unsupported version %d", ctx->frame_hdr.version); + + if (ctx->frame_hdr.is_keyframe) + if (ctx->frame_hdr.kf.scale_w || ctx->frame_hdr.kf.scale_h) + vpx_internal_error(&ctx->error, VPX_CODEC_UNSUP_BITSTREAM, + "Spatial resampling not supported."); + + + +} + + vpx_codec_err_t vp8_parse_frame_header(const unsigned char *data, unsigned int sz, @@ -52,3 +81,20 @@ vp8_parse_frame_header(const unsigned char *data, return VPX_CODEC_OK; } + + +vpx_codec_err_t +vp8_dixie_decode_frame(struct vp8_decoder_ctx *ctx, + const unsigned char *data, + unsigned int sz) +{ + volatile struct vp8_decoder_ctx *ctx_ = ctx; + + ctx->error.error_code = VPX_CODEC_OK; + ctx->error.has_detail = 0; + + if (!setjmp(ctx->error.jmp)) + decode_frame(ctx, data, sz); + + return ctx_->error.error_code; +} diff --git a/vp8/dixie/dixie.h b/vp8/dixie/dixie.h index 9eb45c2d4a..5901c5eaf5 100644 --- a/vp8/dixie/dixie.h +++ b/vp8/dixie/dixie.h @@ -27,9 +27,25 @@ struct vp8_frame_hdr } kf; }; + +struct vp8_decoder_ctx +{ + struct vpx_internal_error_info error; + + struct vp8_frame_hdr frame_hdr; +}; + + vpx_codec_err_t vp8_parse_frame_header(const unsigned char *data, unsigned int sz, struct vp8_frame_hdr *hdr); + +vpx_codec_err_t +vp8_dixie_decode_frame(struct vp8_decoder_ctx *ctx, + const unsigned char *data, + unsigned int sz); + + #endif diff --git a/vp8/vp8_dixie_iface.c b/vp8/vp8_dixie_iface.c index 612c262d2e..af118696e8 100644 --- a/vp8/vp8_dixie_iface.c +++ b/vp8/vp8_dixie_iface.c @@ -25,6 +25,7 @@ struct vpx_codec_alg_priv vpx_codec_priv_t base; vpx_codec_dec_cfg_t cfg; vp8_stream_info_t si; + struct vp8_decoder_ctx decoder_ctx; vpx_image_t img; int img_setup; int img_avail; @@ -142,9 +143,11 @@ static vpx_codec_err_t vp8_decode(vpx_codec_alg_priv_t *ctx, { vpx_codec_err_t res = VPX_CODEC_OK; - ctx->img_avail = 0; - + res = vp8_dixie_decode_frame(&ctx->decoder_ctx, data, data_sz); + if(res) + update_error_state(ctx, &ctx->decoder_ctx.error); + ctx->img_avail = 0; return res; } -- GitLab