ref: bcb97ec647baedea85444ba89b1b1d9f551d5875
parent: cedd19c187b6710af3170b7ea84e04755d52374d
parent: 6a2e9ef20aed3b87259e9491fc76c0b83a76ab3c
author: James Zern <[email protected]>
date: Tue Aug 12 17:11:11 EDT 2014
Merge "vpx_codec_decode: check data size"
--- /dev/null
+++ b/test/decode_api_test.cc
@@ -1,0 +1,59 @@
+/*
+ * Copyright (c) 2014 The WebM project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#include "third_party/googletest/src/include/gtest/gtest.h"
+
+#include "./vpx_config.h"
+#include "vpx/vp8dx.h"
+#include "vpx/vpx_decoder.h"
+
+namespace {
+
+#define NELEMENTS(x) static_cast<int>(sizeof(x) / sizeof(x[0]))
+
+TEST(DecodeAPI, InvalidParams) {
+ static const vpx_codec_iface_t *kCodecs[] = {
+#if CONFIG_VP8_DECODER
+ &vpx_codec_vp8_dx_algo,
+#endif
+#if CONFIG_VP9_DECODER
+ &vpx_codec_vp9_dx_algo,
+#endif
+ };
+ uint8_t buf[1] = {0};
+ vpx_codec_ctx_t dec;
+
+ EXPECT_EQ(VPX_CODEC_INVALID_PARAM, vpx_codec_dec_init(NULL, NULL, NULL, 0));
+ EXPECT_EQ(VPX_CODEC_INVALID_PARAM, vpx_codec_dec_init(&dec, NULL, NULL, 0));
+ EXPECT_EQ(VPX_CODEC_INVALID_PARAM, vpx_codec_decode(NULL, NULL, 0, NULL, 0));
+ EXPECT_EQ(VPX_CODEC_INVALID_PARAM, vpx_codec_decode(NULL, buf, 0, NULL, 0));
+ EXPECT_EQ(VPX_CODEC_INVALID_PARAM,
+ vpx_codec_decode(NULL, buf, NELEMENTS(buf), NULL, 0));
+ EXPECT_EQ(VPX_CODEC_INVALID_PARAM,
+ vpx_codec_decode(NULL, NULL, NELEMENTS(buf), NULL, 0));
+ EXPECT_EQ(VPX_CODEC_INVALID_PARAM, vpx_codec_destroy(NULL));
+ EXPECT_TRUE(vpx_codec_error(NULL) != NULL);
+
+ for (int i = 0; i < NELEMENTS(kCodecs); ++i) {
+ EXPECT_EQ(VPX_CODEC_INVALID_PARAM,
+ vpx_codec_dec_init(NULL, kCodecs[i], NULL, 0));
+
+ EXPECT_EQ(VPX_CODEC_OK, vpx_codec_dec_init(&dec, kCodecs[i], NULL, 0));
+ EXPECT_EQ(VPX_CODEC_UNSUP_BITSTREAM,
+ vpx_codec_decode(&dec, buf, NELEMENTS(buf), NULL, 0));
+ EXPECT_EQ(VPX_CODEC_INVALID_PARAM,
+ vpx_codec_decode(&dec, NULL, NELEMENTS(buf), NULL, 0));
+ EXPECT_EQ(VPX_CODEC_INVALID_PARAM,
+ vpx_codec_decode(&dec, buf, 0, NULL, 0));
+
+ EXPECT_EQ(VPX_CODEC_OK, vpx_codec_destroy(&dec));
+ }
+}
+
+} // namespace
--- a/test/test.mk
+++ b/test/test.mk
@@ -59,6 +59,7 @@
LIBVPX_TEST_SRCS-$(CONFIG_DECODERS) += webm_video_source.h
endif
+LIBVPX_TEST_SRCS-$(CONFIG_DECODERS) += decode_api_test.cc
LIBVPX_TEST_SRCS-$(CONFIG_DECODERS) += invalid_file_test.cc
LIBVPX_TEST_SRCS-$(CONFIG_DECODERS) += test_vector_test.cc
--- a/vpx/src/vpx_decoder.c
+++ b/vpx/src/vpx_decoder.c
@@ -113,7 +113,7 @@
/* Sanity checks */
/* NULL data ptr allowed if data_sz is 0 too */
- if (!ctx || (!data && data_sz))
+ if (!ctx || (!data && data_sz) || (data && !data_sz))
res = VPX_CODEC_INVALID_PARAM;
else if (!ctx->iface || !ctx->priv)
res = VPX_CODEC_ERROR;