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

Crash Bug: Using certain paths, ignoreGlobs may cause the Node process to crash. #194

Open
effectivecui opened this issue Nov 27, 2024 · 1 comment

Comments

@effectivecui
Copy link

effectivecui commented Nov 27, 2024

For example, I run this code snippet using nodejs 16

const watcher = require('@parcel/watcher');
const path = require('path');

const watchPath = path.join(process.cwd(), 'hello')
const ignore = ['D:\\Users\\12234\\**']

// Subscribe to events
watcher.subscribe(watchPath, (err, events) => {
  console.log(events);
}, {
    ignore
});
process.on('uncaughtException', (e)=>{
    console.log('uncaughtException', e)
})

process.on('unhandledRejection', (e)=>{
    console.log('unhandledRejection', e)
})

Then, It will show me an unexpected result and crashed

Regex error: The expression contained an invalid escaped character, or a trailing escape.

Finally, I found the bug in src/binding.cc

Glob::Glob(std::string raw) {
  mRaw = raw;
  mHash = std::hash<std::string>()(raw);
  #ifndef __wasm32__
    mRegex = std::regex(raw);
  #endif
}

// something else


std::unordered_set<Glob> getIgnoreGlobs(Env env, Value opts) {
  std::unordered_set<Glob> result;

  if (opts.IsObject()) {
    Value v = opts.As<Object>().Get(String::New(env, "ignoreGlobs"));
    if (v.IsArray()) {
      Array items = v.As<Array>();
      for (size_t i = 0; i < items.Length(); i++) {
        Value item = items.Get(Number::New(env, i));
        if (item.IsString()) {
          auto key = item.As<String>().Utf8Value();

          // This line will throw regex error when key don't match the regex rule.
          result.emplace(key);

        }
      }
    }
  }

  return result;
}

Now, I try to solve this bug.

@effectivecui effectivecui changed the title ignoreGlobs will make the process of node crash when use some path on windows 11 23H Using certain paths on Windows 11 23H, ignoreGlobs may cause the Node process to crash. Nov 27, 2024
@effectivecui effectivecui changed the title Using certain paths on Windows 11 23H, ignoreGlobs may cause the Node process to crash. Using certain paths on Windows 11 23H2, ignoreGlobs may cause the Node process to crash. Nov 27, 2024
@effectivecui effectivecui changed the title Using certain paths on Windows 11 23H2, ignoreGlobs may cause the Node process to crash. Using certain paths, ignoreGlobs may cause the Node process to crash. Nov 27, 2024
@effectivecui effectivecui changed the title Using certain paths, ignoreGlobs may cause the Node process to crash. Crash Bug: Using certain paths, ignoreGlobs may cause the Node process to crash. Nov 27, 2024
@effectivecui
Copy link
Author

pr: #195

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

No branches or pull requests

1 participant