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

Segmentation Fault destructuring with @each #3078

Closed
richworx opened this issue Mar 30, 2020 · 2 comments · Fixed by #3088
Closed

Segmentation Fault destructuring with @each #3078

richworx opened this issue Mar 30, 2020 · 2 comments · Fixed by #3088

Comments

@richworx
Copy link

richworx commented Mar 30, 2020

This bug was observed with libsass 3.5.4 (node-sass 4.13.1)

  • NPM version: 6.13.4
  • Node version: v12.16.1
  • Node Process:
    • node: '12.16.1',
    • v8: '7.8.279.23-node.31',
    • uv: '1.34.0',
    • zlib: '1.2.11',
    • brotli: '1.0.7',
    • ares: '1.15.0',
    • modules: '72',
    • nghttp2: '1.40.0',
    • napi: '5',
    • llhttp: '2.0.4',
    • http_parser: '2.9.3',
    • openssl: '1.1.1d',
    • cldr: '35.1',
    • icu: '64.2',
    • tz: '2019c',
    • unicode: '12.1'
  • Node Platform: linux
  • Node architecture: x64
  • node-sass version:
    • node-sass 4.13.1 (Wrapper) [JavaScript]
    • libsass 3.5.4 (Sass Compiler) [C/C++]
  • npm node-sass versions:
    • my-web-app@0.1.0 /path/
      └── node-sass@4.13.1

Bug Description:
Running node-sass to compile the following code results in a segmentation fault in Ubuntu. In particular, the fault seems to be caused by trying to access a variable obtained using an @each statement to destructure a list of lists when the inner-list does not have enough elements to assign to all destructured variables.

The expected behavior of the SASS compiler (based on official documentation) when there aren't enough elements in the list is to simply assign null to any remaining variables in the @each statement.

Note that the segfault only seems to occur when the @each is inside a function. This is demonstrated by the debug output of the code below -- the @each statement in the root scope works as expected with no error. However, when the test function is called, the @each statement inside it destructures the variables $a and $b correctly (and these can be output correctly by @debug), but when attempt is made to access $c (for which there is no corresponding element in the list), the segfault occurs.

SCSS code:

@debug "Works fine outside a function.";
@each $a, $b, $c in (A B,) {
  @debug a $a;
  @debug b $b;
  @debug c $c;
}

@function test1() {
  @each $a, $b, $c in (A B,) {
    @debug a $a;
    @debug b $b;
    @debug c $c;
  }
  @return 0;
}
@debug "Segfault happens in function call.";
$var:  test1();

Output of node-sass compilation:

stdin:1 DEBUG: Works fine outside a function.
stdin:3 DEBUG: a A
stdin:4 DEBUG: b B
stdin:5 DEBUG: c null
stdin:16 DEBUG: Segfault happens in function call.
stdin:10 DEBUG: a A
stdin:11 DEBUG: b B
Segmentation fault (core dumped)

I originally had this problem in Ubuntu running on WSL so I thought it might be a WSL issue, but I have reproduced the same bug on a "real" Ubuntu 16.04.6 LTS.
I installed node-sass (at project-level, not globally) with yarn 1.22.1 and am running it with cat FILE | npx node-sass.

@richworx richworx changed the title Segmentation Fault with @each on WSL Segmentation Fault destructuring with @each Mar 30, 2020
@nschonni nschonni transferred this issue from sass/node-sass Mar 30, 2020
@richworx
Copy link
Author

@nschonni Are you sure this is specifically Libsass and not anything to do with node?
I also want to note that I have been able to reproduce this on different versions of node (e.g. v10.18.0) and different operating systems. I would be surprised if others have not already observed it.

@nschonni
Copy link
Collaborator

Anything that has to do with the compilation of Sass is done by Libsass, so nothing in node-sass is likely something that can address this

mgreter added a commit to mgreter/libsass that referenced this issue May 1, 2020
mgreter added a commit to mgreter/libsass that referenced this issue May 1, 2020
Fixes sass#3078

It seems the ternary is returning the type of the second argument.
This means that the first one was first upgraded to a shared object,
and once assigned to a normal pointer, it got prematurely collected.
@mgreter mgreter self-assigned this May 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants