]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
In the fuzz test, improve the calculation of damaging bytes so as to
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Tue, 28 Jun 2011 05:20:00 +0000 (01:20 -0400)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Tue, 28 Jun 2011 05:20:00 +0000 (01:20 -0400)
make at least one byte damage of the sample file even if its size is less than 100 bytes.

SVN-Revision: 3440

libarchive/test/test_fuzz.c

index f810fbeb5fa12ad938dbda572fd70e3ad867afa3..978898ee6729511b4db18cccb5ce32d57da028b5 100644 (file)
@@ -89,7 +89,7 @@ DEFINE_TEST(test_fuzz)
                struct archive *a;
                char *rawimage, *image;
                size_t size;
-               int i;
+               int i, q;
 
                extract_reference_file(filename);
                if (files[n].uncompress) {
@@ -136,7 +136,9 @@ DEFINE_TEST(test_fuzz)
 
                        /* Fuzz < 1% of the bytes in the archive. */
                        memcpy(image, rawimage, size);
-                       numbytes = (int)(rand() % (size / 100));
+                       q = size / 100;
+                       if (!q) q = 1;
+                       numbytes = (int)(rand() % q);
                        for (j = 0; j < numbytes; ++j)
                                image[rand() % size] = (char)rand();