Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ufuzz failure #5352

Closed
alexlamsl opened this issue Feb 12, 2022 · 5 comments · Fixed by #5353
Closed

ufuzz failure #5352

alexlamsl opened this issue Feb 12, 2022 · 5 comments · Fixed by #5353
Labels

Comments

@alexlamsl
Copy link
Collaborator

// original code
// (beautified)
var _calls_ = 10, a = 100, b = 10, c = 0;

function f0(let_1, yield_2) {
    {
        var expr1 = {
            var: a++ + [ , typeof await !== "undefined", --b + (let_1 && let_1.length), (c = c + 1) + let_1, a++ + (--_calls_ >= 0 && new class C0 {
                c = b = a;
                [(1 ?? 23..toString()) * ([] !== -1) | (c = c + 1, 25 < 4)](b_1, undefined, NaN_2) {
                    let Infinity_2 = (c = c + 1) + (typeof f1 == "function" && --_calls_ >= 0 && f1((c = 1 + c, 
                    ("undefined" * "c" === (c = c + 1, null)) <= ((c = c + 1, 4) < "a" + 24..toString()))));
                    {
                        var brake2 = 5;
                        do {
                            c = 1 + c, ((c = c + 1, [ , 0 ].length === 2) ^ /[a2][^e]+$/ == ([ , 0 ].length === 2)) != ("a" === 38..toString() && {} % 23..toString());
                        } while ((c = 1 + c, (Object.isExtensible(Infinity_2) && (Infinity_2[--b + (undefined && undefined[c = 1 + c, 
                        ("undefined" + 2, -4 >> "c") | (Object.isExtensible(NaN_2) && (NaN_2[void function b_1() {
                        }()] &&= (38..toString() == "bar") <= ("a" | Infinity)))])] %= (Object.isExtensible(undefined) && (undefined[c = 1 + c, 
                        ~(2 !== 0) | (-1 ^ true) != (false || "bar")] = [ , 0 ].length === 2 ?? NaN)) >= -4 * 23..toString())) / ((this - "undefined") * (3 < "a"))) && --brake2 > 0);
                    }
                    this[typeof f1 == "function" && --_calls_ >= 0 && f1(25)] = (1 + 3, 
                    -3 >> this) & ("undefined" << "function" & NaN < NaN);
                    L290675: for (var brake4 = 5; (c = 1 + c, ((c = c + 1, true) ^ "number" >> null) !== (c = c + 1, 
                    5 + (-42n).toString())) && brake4 > 0; --brake4) {
                        c = 1 + c, Object.isExtensible(Infinity_2) && (Infinity_2.undefined = ([ , 0 ][1] === 22, 
                        NaN <= -0) & (Infinity, 38..toString()) - (Object.isExtensible(yield_2) && (yield_2[c = 1 + c, 
                        0 >> "bar" <= (Infinity !== "") == ((Infinity && -2) | (4 || ""))] ^= null !== 4)));
                    }
                }
                static "\t" = {
                    [(c = 1 + c, (null ^ {}) <= (NaN > 22) < +(5 == "number"))]: (c = 1 + c, 
                    ((-5 || 5) !== -0 % "undefined") << ((-3 !== 25) > (false ?? 2))),
                    c: (c = 1 + c, (null & NaN) % (22 * /[a2][^e]+$/) - ((Infinity, 
                    [ 3n ][0] > 2) === null >>> 0)),
                    1.5: (c = 1 + c, (c = c + 1, (-42n).toString() === 25) * (-1 !== null !== "number" << "a")),
                    ...yield_2
                }.null;
                [(c = c + 1) + function(NaN_1, bar, a) {
                    c = 1 + c, (null === {}) / (false % 2) | (null < ([ , 0 ].length === 2) ?? "object" * NaN);
                    c = 1 + c, c = c + 1, Object.isExtensible(NaN_1) && ([ NaN_1[--b + {
                        bar: bar
                    }] ] = [ "b" <= false ?? 5 >>> -2 ]);
                    c = 1 + c, (this ^ "function" && this >> "foo") % (-5 / [ , 0 ][1] < (Infinity ?? 0));
                    c = 1 + c, (-0 >> "undefined") + (null <= {}) - (5 * false > (4 != -3));
                }((c = 1 + c, (let_1 = -5 >= -2) + (this || 38..toString()) !== "b" >> "undefined" >>> ([ , 0 ].length === 2 == "foo")))] = a++ + (b = a);
            }(25, --b + {
                "-2": (c = 1 + c, ("bar" & null ^ (23..toString() | 5)) > ((c = c + 1, 
                -3) ^ (yield_2 && (yield_2[c = 1 + c, let_1 && (let_1[a++ + {}.value] += ([ , 0 ][1] << "number" && ([ , 0 ].length === 2) >>> 2) ** ((undefined | "undefined") >= -0 - 22))] += 24..toString() !== true)))),
                set: (c = 1 + c, (25 !== {} !== (let_1 = -3 ^ /[a2][^e]+$/)) >= (yield_2 && (yield_2.async = 22 % "")) / (yield_2 >>>= /[a2][^e]+$/ > -0)),
                1.5: (c = 1 + c, (c = c + 1, 1 >> "c") <= -({} > null)),
                value: (c = 1 + c, -4 ^ null | this + Infinity && (this <= "a", 
                undefined || -4))
            }[--b + (yield_2 && yield_2[c = 1 + c, (c = c + 1, true ^ null) | ("" | [ , 0 ].length === 2) !== "" - "a"])])) ]
        }.next;
        for (var key1 in expr1) {
        }
    }
}

var b_2 = f0(-2, 3);

console.log(null, a, b, c, Infinity, NaN, undefined);
// uglified code
// (beautified)
var _calls_ = 10, a = 100, b = 10, c = 0;

function f0(let_1, yield_2) {
    a++, --b, let_1 && let_1.length, c += 1, a++, 0 <= --_calls_ && new class {
        c = b = a;
        [+(-1 !== []) | (c += 1, !1)](b_1, undefined, NaN_2) {
            let Infinity_2 = (c += 1) + ("function" == typeof f1 && 0 <= --_calls_ && f1((NaN === null) <= (c = (c = 1 + c) + 1 + 1, 
            4 < "a" + 24..toString())));
            for (var brake2 = 5; c = 1 + c, c += 1, "a" === 38..toString() && 23..toString(), 
            c = 1 + c, (Object.isExtensible(Infinity_2) && (Infinity_2[--b + (undefined && undefined[c = 1 + c, 
            -4 | (Object.isExtensible(NaN_2) && (NaN_2[void 0] &&= ("bar" == 38..toString()) <= 0))])] %= (Object.isExtensible(undefined) && (undefined[c = 1 + c, 
            -1] = 2 === [ , 0 ].length ?? NaN)) >= -4 * 23..toString())) / (!1 * (this - "undefined")) && 0 < --brake2; ) {}
            this["function" == typeof f1 && 0 <= --_calls_ && f1(25)] = -3 >> this & 0;
            for (var brake4 = 5; (0 ^ !0) !== (c = (c = 1 + c) + 1 + 1, 5 + (-42n).toString()) && 0 < brake4; --brake4) {
                c = 1 + c, Object.isExtensible(Infinity_2) && (Infinity_2.undefined = !1 & 38..toString() - (Object.isExtensible(yield_2) && (yield_2[c = 1 + c, 
                !1] ^= !0)));
            }
        }
        static "\t" = {
            [(c = 1 + c, (null ^ {}) <= !1 < 0)]: (c = 1 + c, 2),
            c: (c = 1 + c, NaN - (2 < 3n === 0)),
            1.5: (c = 1 + c, !0 * (c += 1, 25 === (-42n).toString())),
            ...yield_2
        }.null;
        [(c += 1) + (c = 1 + c, let_1 = (let_1 = !1) + (this || 38..toString()) !== 0 >>> (2 === [ , 0 ].length == "foo"), 
        c = 1 + (c = 1 + c), c += 1, Object.isExtensible(let_1) && ([ let_1[--b + {
            bar: void 0
        }] ] = [ !1 ]), void (c = 1 + (c = 1 + c)))] = a++ + (b = a);
    }(25, --b + {
        "-2": (c = 1 + c, (0 ^ (5 | 23..toString())) > (c += 1, -3 ^ (yield_2 && (yield_2[c = 1 + c, 
        let_1 && (let_1[a++ + {}.value] += 0)] += !0 !== 24..toString())))),
        set: (c = 1 + c, (25 !== {} !== (let_1 = -3)) >= (yield_2 && (yield_2.async = NaN)) / (yield_2 >>>= !1)),
        1.5: (c = 1 + c, 1 <= -(null < {})),
        value: (c = 1 + (c += 1), -4 | this + 1 / 0 && -4)
    }[--b + (yield_2 && yield_2[c = 1 + c, c += 1, 1 | NaN !== ("" | 2 === [ , 0 ].length)])]);
}

var b_2 = f0(-2, 3);

console.log(null, a, b, c, 1 / 0, NaN, void 0);
original result:
null 103 103 23 Infinity NaN undefined

uglified result:
null 104 104 23 Infinity NaN undefined
// reduced test case (output will differ)

// (beautified)
function f0(let_1) {
    new class C0 {
        [function(NaN_1) {
            Object(NaN_1);
        }(console.log())] = 0;
    }(let_1[0]);
}

f0(3);
// output: 
// 
// minify: TypeError: Cannot read properties of undefined (reading '0')
// options: {
//   "mangle": false,
//   "output": {
//     "v8": true
//   },
//   "validate": true
// }
minify(options):
{
  "mangle": false,
  "output": {
    "v8": true
  }
}

Suspicious compress options:
  inline
  merge_vars
  sequences
  side_effects
  unused
@alexlamsl alexlamsl added the bug label Feb 12, 2022
@alexlamsl
Copy link
Collaborator Author

@kzc TIL

$ echo 'new function({[console.log("func arg")]:a}){}([console.log("func call")]);' | node
func call
func arg
$ echo 'new class{[console.log("class field")]}(console.log("class call"));' | node
class field
class call

@kzc
Copy link
Contributor

kzc commented Feb 12, 2022

I don't even know what that is.

$ echo 'new class {[1]; 2;}' | node
$ 
$ echo 'new class {[1]; 2;}' | acorn --module --ecma2022 | egrep -v 'start|end|raw'
{
  "type": "Program",
  "body": [
    {
      "type": "ExpressionStatement",
      "expression": {
        "type": "NewExpression",
        "callee": {
          "type": "ClassExpression",
          "id": null,
          "superClass": null,
          "body": {
            "type": "ClassBody",
            "body": [
              {
                "type": "PropertyDefinition",
                "static": false,
                "computed": true,
                "key": {
                  "type": "Literal",
                  "value": 1,
                },
                "value": null
              },
              {
                "type": "PropertyDefinition",
                "static": false,
                "computed": false,
                "key": {
                  "type": "Literal",
                  "value": 2,
                },
                "value": null
              }
            ]
          }
        },
        "arguments": []
      }
    }
  ],
  "sourceType": "module"
}

A property key without a value. What else can be in a PropertyDefinition?

alexlamsl added a commit to alexlamsl/UglifyJS that referenced this issue Feb 12, 2022
@alexlamsl
Copy link
Collaborator Author

Oh that value-less property is one of the first oddity I encountered when implementing support for class 🤣

@kzc
Copy link
Contributor

kzc commented Feb 12, 2022

What the heck is this?

$ echo 'var x = 1; console.log(new class {[x] = 2; 3 = 4;});' | node
{ '1': 2, '3': 4 }
$ echo 'var x = 1; console.log(new class {[[[x]]] = 2; 3 = 4;});' | node
{ '1': 2, '3': 4 }
$ echo 'var x = 1; console.log(new class {[[x,0]] = 2; 3 = 4;});' | node
{ '3': 4, '1,0': 2 }

So it appears if there's a computed key, its toString() is used. This is useful why?

@alexlamsl
Copy link
Collaborator Author

This is useful why?

You are preaching to the choir − I guess the saving grace would be that they do the same for computed keys in object literal & destructuring syntax?

alexlamsl added a commit that referenced this issue Feb 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants