Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions test/fuzz/Fuzz.hx
Original file line number Diff line number Diff line change
Expand Up @@ -569,15 +569,20 @@ class Fuzz {

/**
Whether two values have different texts from canon(). A value that
takes more than CANON_WORK steps is not compared: the serializer's
references can share a value at every level, as "ay1:aoy0:r0gr0h"
does, and the depth cut-off alone leaves 2^32 steps.
takes more than CANON_WORK steps or CANON_TEXT characters is not
compared: the serializer's references can share a value at every
level, as "ay1:aoy0:r0gr0h" does, and the depth cut-off alone leaves
2^32 steps. In a map whose key and value both hold the map, as
"Moy0:r0gr0h", the text also grows at each level, so 100,000 steps
could build hundreds of millions of characters.
**/
static function differ(a:Dynamic, b:Dynamic):Bool {
try {
canonLeft = CANON_WORK;
canonTextLeft = CANON_TEXT;
var ta = canon(a);
canonLeft = CANON_WORK;
canonTextLeft = CANON_TEXT;
return ta != canon(b);
} catch (e:CanonTooBig) {
return false;
Expand All @@ -587,6 +592,16 @@ class Fuzz {
static inline var CANON_WORK = 100000;
static var canonLeft = 0;

/**
The characters of text canon() builds for a value at most. Each level
copies the texts below it into its own, so a text counts once for
each level that holds it, as it is allocated. Without references or
runs of nulls, 4096 bytes of input stay under a third of this: a byte
gives at most ten characters ("m" gives "-Infinity,"), at 33 levels.
**/
static inline var CANON_TEXT = 1 << 22;
static var canonTextLeft = 0;

/**
A text for a value that does not depend on the order fields and map
keys come out in. Shared and cyclic values from the serializer's
Expand All @@ -597,6 +612,13 @@ class Fuzz {
throw new CanonTooBig();
if (depth > 32)
return "...";
var text = canonText(v, depth);
if ((canonTextLeft -= text.length) < 0)
throw new CanonTooBig();
return text;
}

static function canonText(v:Dynamic, depth:Int):String {
function sorted(items:Array<String>) {
items.sort(Reflect.compare);
return items.join(",");
Expand Down
Binary file not shown.
Loading