[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2] master 8fb9d22: [ftfuzzer] Replace `rand' with an xorshift a
From: |
Werner LEMBERG |
Subject: |
[freetype2] master 8fb9d22: [ftfuzzer] Replace `rand' with an xorshift algorithm. |
Date: |
Fri, 30 Dec 2016 18:52:08 +0000 (UTC) |
branch: master
commit 8fb9d22a6b0131f05490d6314a28f141ab1eb85f
Author: Werner Lemberg <address@hidden>
Commit: Werner Lemberg <address@hidden>
[ftfuzzer] Replace `rand' with an xorshift algorithm.
* src/tools/ftfuzzer/ftfuzzer.cc: Don't include `stdlib.h'.
(Random): Implement and use a 32bit `xorshift' algorithm.
---
ChangeLog | 7 +++++++
src/tools/ftfuzzer/ftfuzzer.cc | 18 +++++++++++++-----
2 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 91a30e6..8cbe68f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2016-12-30 Werner Lemberg <address@hidden>
+ [ftfuzzer] Replace `rand' with an xorshift algorithm.
+
+ * src/tools/ftfuzzer/ftfuzzer.cc: Don't include `stdlib.h'.
+ (Random): Implement and use a 32bit `xorshift' algorithm.
+
+2016-12-30 Werner Lemberg <address@hidden>
+
[ftfuzzer] Restrict number of tested bitmap strikes.
Malformed fonts often have large values for the number of bitmap
diff --git a/src/tools/ftfuzzer/ftfuzzer.cc b/src/tools/ftfuzzer/ftfuzzer.cc
index 535be3f..31834a5 100644
--- a/src/tools/ftfuzzer/ftfuzzer.cc
+++ b/src/tools/ftfuzzer/ftfuzzer.cc
@@ -22,7 +22,6 @@
#include <assert.h>
#include <stdint.h>
-#include <stdlib.h>
#include <memory>
#include <vector>
@@ -88,6 +87,8 @@
int t; // total number of values so far
int m; // number of selected values so far
+ uint32_t r; // the current pseudo-random number
+
Random( int n_,
int N_ )
: n( n_ ),
@@ -96,10 +97,10 @@
t = 0;
m = 0;
- // ideally, this should depend on the input file,
+ // Ideally, this should depend on the input file,
// for example, taking the sha256 as input;
- // however, this is overkill for fuzzying tests
- srand( 12345 );
+ // however, this is overkill for fuzzying tests.
+ r = 12345;
}
int get()
@@ -108,7 +109,14 @@
return -1;
Redo:
- double U = double(rand()) / RAND_MAX;
+ // We can't use `rand': different C libraries might provide
+ // different implementations of this function. As a replacement,
+ // we use a 32bit version of the `xorshift' algorithm.
+ r ^= r << 13;
+ r ^= r >> 17;
+ r ^= r << 5;
+
+ double U = double( r ) / UINT32_MAX;
if ( ( N - t ) * U >= ( n - m ) )
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2] master 8fb9d22: [ftfuzzer] Replace `rand' with an xorshift algorithm.,
Werner LEMBERG <=