[FFmpeg-devel] [PATCH] remove unused and broken test program in libavutil/base64.c
Stefano Sabatini
stefano.sabatini-lala
Sat Jan 24 21:48:16 CET 2009
On date Friday 2009-01-23 09:53:41 +0100, Diego Biurrun encoded:
> On Thu, Jan 22, 2009 at 12:09:19AM +0100, Stefano Sabatini wrote:
> > On date Thursday 2009-01-22 00:04:13 +0100, Diego Biurrun encoded:
> > > I found some more cruft in the attic: a forgotten test program in
> > > libavutil/base64.c. It never compiled, not even the day it was
> > > committed, since it calls av_base64_encode() with a wrong number
> > > of parameters.
> > >
> > > OK to remove?
> >
> > Why not to simply fix it?
>
> The question is whether it is worth the trouble. Given that it is
> proven that nobody ever used this program, I believe it to be
> doubtful that anybody will in the future.
>
> Of course you can have a stab at fixing it...
It turned out in a semi-complete rewrite of the test program, anyway I
don't feel like to send a patch and discuss every single change, if
it's possible to simply replace the new code I'll happily do it.
Anyway here it is the result of the result of the last test:
Encoding/decoding tests on constant with an invalid termination data
Checking for validity of invalid encoded sequence 'M'...considered valid, test failed!
Checking for validity of invalid encoded sequence 'M=M'...considered valid, test failed!
Checking for validity of invalid encoded sequence 'MQ==='...considered valid, test failed!
Comment in the original code:
// these are invalid strings, that it currently decodes (which it probably shouldn't?)
My opinion is that av_base64_decode() should fail on invalid input
sequences.
Follows the new test code:
----------8<--------------------8<--------------------------------
//#define TEST
#ifdef TEST
#include "log.h"
#include "mem.h"
#undef printf
#undef srand
#undef rand
int main()
{
int numerr = 0;
struct test {
void *data;
int data_size;
const char *encoded;
} *t, tests[] = {
{ "", 0, ""},
{ "1", 1, "MQ=="},
{ "22", 2, "MjI="},
{ "333", 3, "MzMz"},
{ "4444", 4, "NDQ0NA=="},
{ "55555", 5, "NTU1NTU="},
{ "abc:def", 7, "YWJjOmRlZg=="},
{ NULL}
};
printf("Encoding/decoding tests on constant data\n");
for (t = tests; t->data; t++) {
char encoded[1024];
uint8_t data[1024];
int data_size;
printf("Encoding '%s'... ", (char *)t->data);
if (av_base64_encode(encoded, sizeof(encoded), t->data, t->data_size)) {
printf("encoded to '%s'\n", encoded);
if (strcmp(encoded, t->encoded) != 0) {
printf("failed: '%s' != '%s'\n", encoded, t->encoded);
numerr++;
}
}
printf("Decoding '%s'... ", t->encoded);
data_size = av_base64_decode(data, t->encoded, sizeof(data));
if (data_size != t->data_size) {
printf("failed: len %d != %d\n", data_size, t->data_size);
numerr++;
} else if (memcmp(data, t->data, t->data_size) != 0) {
printf("failed: data differs\n");
numerr++;
} else {
printf("decoded to '%s'\n", (char *)t->data);
}
}
printf("\n");
printf("Encoding/decoding tests on random data\n");
{
int test_count;
srand(123141); // time(NULL));
for (test_count = 0; test_count < 100; test_count++) {
int data_size = rand() % 1024;
uint8_t *data = (uint8_t *)av_malloc(data_size);
char encoded[2048];
int i;
for (i = 0; i < data_size; i++)
data[i] = rand() % 255;
printf("Test %d: data size %d bytes... ", test_count, data_size);
if (av_base64_encode(encoded, sizeof(encoded), data, data_size)) {
int size = data_size + 10; // try without 10 as well
uint8_t *data2 = av_malloc(size);
if (data2) {
int data2_size = av_base64_decode(data2, encoded, size);
if (data2_size < 0)
printf("Invalid input data sequence: '%s'\n", encoded);
else if (data2_size != data_size) {
printf("decoded/encoded size mismatch (%d != %d)\n", data2_size, data_size);
} else {
if (memcmp(data2, data, data_size)) {
printf("failed (Data differs)!\n");
} else {
printf("passed!\n");
}
}
av_free(data2);
}
}
}
}
printf("\n");
printf("Encoding/decoding tests on constant with an invalid termination data\n");
{
uint8_t data[32];
int i;
char *encoded[] = { "M", "M=M", "MQ===" };
for (i=0; i < FF_ARRAY_ELEMS(encoded); i++) {
printf("Checking for validity of invalid encoded sequence '%s'...", encoded[i]);
if (av_base64_decode(data, encoded[i], sizeof(data)) >= 0) {
printf("considered valid, test failed!\n");
numerr++;
}
else
printf("considered invalid, test passed!\n");
}
}
printf("\n");
return numerr;
}
#endif
----------8<--------------------8<--------------------------------
Regards.
--
FFmpeg = Frightening and Fiendish Magnificient Puristic Ecstatic Ghost
More information about the ffmpeg-devel
mailing list