Giter Club home page Giter Club logo

Comments (3)

yohgaki avatar yohgaki commented on July 24, 2024

It might be good idea to have backtrack/stack limit like PCRE. I briefly checked oniguruma.h and it seems it does not have such API/feature. PHP's PCRE is not affected by the ReDoS mentioned first probably because backtrack limit. (latter one is affected)

from oniguruma.

kkos avatar kkos commented on July 24, 2024

I know the problem.
I have worked on this problem in old days.
If USE_COMBINATION_EXPLOSION_CHECK flag in src/regint.h enabled, it solves several patterns.
However, it does not solve all pattern cases and it become slow.
Therefore, I was not able to use it.

Oniguruma has API limiting stack size. (default 0: unlimited)
onig_set_match_stack_limit_size()
But I don't know how much size is appropriate.

extern int main(int argc, char* argv[])
{
#define MAX_SIZE   1000000

  int len;
  int i;
  char s[MAX_SIZE];

  len = atoi(argv[1]);
  fprintf(stdout, "len: %d\n", len);
  for (i = 0; i < len; i++) {
    s[i] = ' ';
  }
  s[len] = 'a';
  s[len + 1] = '\0';

  exec(ONIG_ENCODING_UTF8, ONIG_ENCODING_UTF8, ONIG_OPTION_NONE,
       "\\s+$", s);
  return 0;
}

$ time ./t 50000
len: 50000
search fail (UTF-8)

real    0m32.140s
user    0m31.550s
sys 0m0.174s
extern int main(int argc, char* argv[])
{
#define MAX_SIZE   1000000

  int len;
  int i;
  char s[MAX_SIZE];

  len = atoi(argv[1]);
  fprintf(stdout, "len: %d\n", len);
  for (i = 0; i < len; i++) {
    s[i] = ' ';
  }
  s[len] = 'a';
  s[len + 1] = '\0';

  onig_set_match_stack_limit_size(30000);

  exec(ONIG_ENCODING_UTF8, ONIG_ENCODING_UTF8, ONIG_OPTION_NONE,
       "\\s+$", s);
  return 0;
}

$ ./t 50000
len: 50000
ERROR: match-stack limit over
  (UTF-8)

from oniguruma.

yohgaki avatar yohgaki commented on July 24, 2024

Oniguruma has API limiting stack size. (default 0: unlimited)
onig_set_match_stack_limit_size()

Thank you for the pointer. I'll add stack limit to PHP :)

from oniguruma.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.