diff --git a/test/fuzz/Fuzz.hx b/test/fuzz/Fuzz.hx index ba67c1ef..fabda1f8 100644 --- a/test/fuzz/Fuzz.hx +++ b/test/fuzz/Fuzz.hx @@ -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; @@ -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 @@ -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) { items.sort(Reflect.compare); return items.join(","); diff --git a/test/fuzz/regressions/serializer/map-holds-itself-in-key-and-value b/test/fuzz/regressions/serializer/map-holds-itself-in-key-and-value new file mode 100644 index 00000000..7c51092b Binary files /dev/null and b/test/fuzz/regressions/serializer/map-holds-itself-in-key-and-value differ