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

Bad output generated by 3.4.9. #3245

Closed
blvd20 opened this issue Sep 2, 2018 · 8 comments · Fixed by #3329
Closed

Bad output generated by 3.4.9. #3245

blvd20 opened this issue Sep 2, 2018 · 8 comments · Fixed by #3329

Comments

@blvd20
Copy link

blvd20 commented Sep 2, 2018

Bug report

Uglify version (3.4.9)

JavaScript input (The source is from protobufjs. )

function utf8_write(string, buffer, offset) {
  var start = offset,
    c1, // character 1
    c2; // character 2
  for (var i = 0; i < string.length; ++i) {
    c1 = string.charCodeAt(i);
    if (c1 < 128) {
      buffer[offset++] = c1;
    } else if (c1 < 2048) {
      buffer[offset++] = c1 >> 6 | 192;
      buffer[offset++] = c1 & 63 | 128;
    } else if ((c1 & 0xFC00) === 0xD800 && ((c2 = string.charCodeAt(i + 1)) & 0xFC00) === 0xDC00) {
      c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF);
      ++i;
      buffer[offset++] = c1 >> 18 | 240;
      buffer[offset++] = c1 >> 12 & 63 | 128;
      buffer[offset++] = c1 >> 6 & 63 | 128;
      buffer[offset++] = c1 & 63 | 128;
    } else {
      buffer[offset++] = c1 >> 12 | 224;
      buffer[offset++] = c1 >> 6 & 63 | 128;
      buffer[offset++] = c1 & 63 | 128;
    }
  }
  return offset - start;
};

JavaScript output

function utf8_write(r, t, e) {
  for (var n, o, a = e, c = 0; c < r.length; ++c)
    n = r.charCodeAt(c),
      t[e++] = n < 128 ? n : (t[e++] = n < 2048 ? n >> 6 | 192 : (55296 == (64512 & n) && 56320 == (64512 & (o = r.charCodeAt(c + 1))) ? (n = 65536 + ((1023 & n) << 10) + (1023 & o),
        ++c,
        t[e++] = n >> 18 | 240,
        t[e++] = n >> 12 & 63 | 128) : t[e++] = n >> 12 | 224,
        n >> 6 & 63 | 128),
        63 & n | 128);
  return e - a
}

The first e++ is wrong.
The output generated by 3.4.8 is fine.

function utf8_write(r, t, e) {
  for (var n, o, a = e, c = 0; c < r.length; ++c)
    (n = r.charCodeAt(c)) < 128 ? t[e++] = n : (n < 2048 ? t[e++] = n >> 6 | 192 : (55296 == (64512 & n) && 56320 == (64512 & (o = r.charCodeAt(c + 1))) ? (n = 65536 + ((1023 & n) << 10) + (1023 & o),
      ++c,
      t[e++] = n >> 18 | 240,
      t[e++] = n >> 12 & 63 | 128) : t[e++] = n >> 12 | 224,
      t[e++] = n >> 6 & 63 | 128),
      t[e++] = 63 & n | 128);
  return e - a
}
@kzc
Copy link
Contributor

kzc commented Sep 2, 2018

With the following lines appended to the input in the top post:

var arr = [];
var size = utf8_write("¯\\_(ツ)_/¯", arr, 0);
console.log(size, JSON.stringify(arr));

Expected:

$ cat input.js | node
13 '[194,175,92,95,40,227,131,132,41,95,47,194,175]'

Actual:

$ uglify-js -V
uglify-js 3.4.9

$ cat input.js | uglify-js -c | node
13 '[175,194,92,95,40,132,131,227,41,95,47,175,194]'

Workaround:

$ cat input.js | uglify-js -c conditionals=0 | node
13 '[194,175,92,95,40,227,131,132,41,95,47,194,175]'

@blvd20
Copy link
Author

blvd20 commented Sep 3, 2018

How about remove this version from NPM ?

@lukeapage
Copy link

Is this the same bug? or should I open a new issue?

A problem with lodash slice when called with no length argument to clone an array

function slice(array, start, end) {
  var length = array == null ? 0 : array.length;
  if (!length) {
    return [];
  }
  if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
    start = 0;
    end = length;
  }
  else {
    start = start == null ? 0 : toInteger(start);
    end = end === undefined ? length : toInteger(end);
  }
  return baseSlice(array, start, end);
}

becomes

                function slice(t, e, n) {
                    var r = null == t ? 0 : t.length;
                    return r ? Ie(t, e, n = n && "number" != typeof n && Vn(t, e, n) ? (e = 0,
                    r) : (e = null == e ? 0 : Wi(e),
                    n === ea ? r : Wi(n))) : []
                }

Now, if e = undefined, then the assignment is moved to inside the parameters, but after the e param

e.g. uglify assumes

function a(b, c) { console.log(b, c); } var d = undefined, e = 1; a(d, e = d = 2);

answers

2
2

but it doesn't - it answers

undefined
2

@fabiosantoscode
Copy link
Contributor

It looks like this error does not affect the terser fork.

@kzc
Copy link
Contributor

kzc commented Oct 31, 2018

conditionals bug introduced in 2bdaca1, ce7e220.

rdunlop added a commit to wyeworks/nucore-open that referenced this issue Nov 1, 2018
mishoo/UglifyJS#3245 documents
a bug which occurs when using compression.

There does not appear to be any way to disable this particular path through the uglifier.
jhanggi pushed a commit to wyeworks/nucore-open that referenced this issue Nov 5, 2018
# Release Notes

Tech task: Revert Uglifier to 4.1.18, due to bug in Uglify 3.4.9

# Additional Context

mishoo/UglifyJS#3245 documents a bug which occurs when using compression.

There does not appear to be any way to disable this particular path through the uglifier.
@pedrofurtado
Copy link

#3278

ColinMcNeil pushed a commit to SquaredLabs/nucore-uconn that referenced this issue Nov 9, 2018
# Release Notes

Tech task: Revert Uglifier to 4.1.18, due to bug in Uglify 3.4.9

# Additional Context

mishoo/UglifyJS#3245 documents a bug which occurs when using compression.

There does not appear to be any way to disable this particular path through the uglifier.
@neelance
Copy link

neelance commented Nov 12, 2018

Edit: See #3278 (comment) and following.

@blvd20
Copy link
Author

blvd20 commented Nov 20, 2018

@mishoo Are you still maintaining this project? Seems this version causing problems all the time since your last release.

joshea0 pushed a commit to SquaredLabs/nucore-uconn that referenced this issue Jan 16, 2019
# Release Notes

Tech task: Revert Uglifier to 4.1.18, due to bug in Uglify 3.4.9

# Additional Context

mishoo/UglifyJS#3245 documents a bug which occurs when using compression.

There does not appear to be any way to disable this particular path through the uglifier.
joshea0 pushed a commit to SquaredLabs/nucore-uconn that referenced this issue Jan 16, 2019
# Release Notes

Tech task: Revert Uglifier to 4.1.18, due to bug in Uglify 3.4.9

# Additional Context

mishoo/UglifyJS#3245 documents a bug which occurs when using compression.

There does not appear to be any way to disable this particular path through the uglifier.
alexlamsl added a commit to alexlamsl/UglifyJS that referenced this issue Mar 12, 2019
alexlamsl added a commit that referenced this issue Mar 12, 2019
fixes #3245
fixes #3257
fixes #3260
fixes #3269
fixes #3271
fixes #3278
fixes #3309
fixes #3319
fixes #3321
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants