History

avcodec/tests/avcodec: Sanity check AVCodec.priv_data_size

Andreas Rheinhardt committed 5 years ago

Commit 2b0f2951 parent 5aac4b61 file · +23 −0Browse files

Unified · Split

libavcodec/tests/avcodec.c+23−0
@@ -16,6 +16,7 @@ · 15 unmodified lines
1616 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1717 */
1818
19+#include "libavutil/opt.h"
1920 #include "libavcodec/codec.h"
2021 #include "libavcodec/codec_desc.h"
2122
@@ -34,6 +35,25 @@ do { \ · 12 unmodified lines
3435 #define ERR(msg) ERR_INTERNAL(msg, )
3536 #define ERR_EXT(msg, ...) ERR_INTERNAL(msg, , __VA_ARGS__)
3637
38+static int priv_data_size_wrong(const AVCodec *codec)
39+{
40+ if (codec->priv_data_size < 0 ||
41+ codec->priv_class && codec->priv_data_size < sizeof(AVClass*))
42+ return 1;
43+ if (!codec->priv_class || !codec->priv_class->option)
44+ return 0;
45+ for (const AVOption *opt = codec->priv_class->option; opt->name; opt++) {
46+ if (opt->offset >= codec->priv_data_size ||
47+ opt->type == AV_OPT_TYPE_CONST && opt->offset != 0 ||
48+ opt->type != AV_OPT_TYPE_CONST && (opt->offset < sizeof(AVClass*) || opt->offset < 0)) {
49+ AV_LOG("Option %s offset %d nonsensical\n",
50+ opt->name, opt->offset);
51+ return 1;
52+ }
53+ }
54+ return 0;
55+}
56+
3757 int main(void){
3858 void *iter = NULL;
3959 const AVCodec *codec = NULL;
@@ -92,6 +112,9 @@ int main(void){ · 52 unmodified lines
92112 if (!!codec->decode + !!codec->receive_frame != 1)
93113 ERR("Decoder %s does not implement exactly one decode API.\n");
94114 }
115+ if (priv_data_size_wrong(codec))
116+ ERR_EXT("Private context of codec %s is impossibly-sized (size %d).",
117+ codec->priv_data_size);
95118 if (!(desc = avcodec_descriptor_get(codec->id))) {
96119 ERR("Codec %s lacks a corresponding descriptor\n");
97120 } else if (desc->type != codec->type)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t