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
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */17 */
18 18
19#include "libavutil/opt.h"
19#include "libavcodec/codec.h"20#include "libavcodec/codec.h"
20#include "libavcodec/codec_desc.h"21#include "libavcodec/codec_desc.h"
21 22
@@ -34,6 +35,25 @@ do { \ · 12 unmodified lines
34#define ERR(msg) ERR_INTERNAL(msg, )35#define ERR(msg) ERR_INTERNAL(msg, )
35#define ERR_EXT(msg, ...) ERR_INTERNAL(msg, , __VA_ARGS__)36#define ERR_EXT(msg, ...) ERR_INTERNAL(msg, , __VA_ARGS__)
36 37
38static 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
37int main(void){57int main(void){
38 void *iter = NULL;58 void *iter = NULL;
39 const AVCodec *codec = NULL;59 const AVCodec *codec = NULL;
@@ -92,6 +112,9 @@ int main(void){ · 52 unmodified lines
92 if (!!codec->decode + !!codec->receive_frame != 1)112 if (!!codec->decode + !!codec->receive_frame != 1)
93 ERR("Decoder %s does not implement exactly one decode API.\n");113 ERR("Decoder %s does not implement exactly one decode API.\n");
94 }114 }
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);
95 if (!(desc = avcodec_descriptor_get(codec->id))) {118 if (!(desc = avcodec_descriptor_get(codec->id))) {
96 ERR("Codec %s lacks a corresponding descriptor\n");119 ERR("Codec %s lacks a corresponding descriptor\n");
97 } else if (desc->type != codec->type)120 } 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