diff options
author | Reimar Döffinger <Reimar.Doeffinger@gmx.de> | 2012-01-20 23:26:10 +0100 |
---|---|---|
committer | Reimar Döffinger <Reimar.Doeffinger@gmx.de> | 2012-01-21 12:04:46 +0100 |
commit | 8650d5faf95e319a59f40e08b2eff67bcbb4bc1a (patch) | |
tree | 58f3ce2a8079a3b60451d2d07a677fece299393a /libavutil/base64.c | |
parent | 77b90f0cd0b702b9ffff55d8612ef8b487705fd6 (diff) | |
download | ffmpeg-8650d5faf95e319a59f40e08b2eff67bcbb4bc1a.tar.gz |
base64: more thorough decode tests.
Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
Diffstat (limited to 'libavutil/base64.c')
-rw-r--r-- | libavutil/base64.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/libavutil/base64.c b/libavutil/base64.c index af4a4200b3..8d18af125c 100644 --- a/libavutil/base64.c +++ b/libavutil/base64.c @@ -136,15 +136,34 @@ static int test_encode_decode(const uint8_t *data, unsigned int data_size, return 1; } - if ((data2_size = av_base64_decode(data2, encoded, max_data2_size)) < 0) { + if ((data2_size = av_base64_decode(data2, encoded, max_data2_size)) != data_size) { printf("Failed: cannot decode the encoded string\n" "Encoded:\n%s\n", encoded); return 1; } + if ((data2_size = av_base64_decode(data2, encoded, data_size)) != data_size) { + printf("Failed: cannot decode with minimal buffer\n" + "Encoded:\n%s\n", encoded); + return 1; + } if (memcmp(data2, data, data_size)) { printf("Failed: encoded/decoded data differs from original data\n"); return 1; } + if (av_base64_decode(NULL, encoded, 0) != 0) { + printf("Failed: decode to NULL buffer\n"); + return 1; + } + if (strlen(encoded)) { + char *end = strchr(encoded, '='); + if (!end) + end = encoded + strlen(encoded) - 1; + *end = '%'; + if (av_base64_decode(NULL, encoded, 0) >= 0) { + printf("Failed: error detection\n"); + return 1; + } + } printf("Passed!\n"); return 0; |