[njs] Fixed RegExp.prototype.[@@split]() with UTF8 strings.

Dmitry Volyntsev xeioex at nginx.com
Fri Jun 11 18:28:40 UTC 2021


details:   https://hg.nginx.org/njs/rev/a0f5719c8d9a
branches:  
changeset: 1658:a0f5719c8d9a
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Fri Jun 11 15:47:37 2021 +0000
description:
Fixed RegExp.prototype.[@@split]() with UTF8 strings.

Found by OSS-Fuzz.

diffstat:

 src/njs_regexp.c         |  3 ++-
 src/test/njs_unit_test.c |  3 +++
 2 files changed, 5 insertions(+), 1 deletions(-)

diffs (26 lines):

diff -r 1c066436ec55 -r a0f5719c8d9a src/njs_regexp.c
--- a/src/njs_regexp.c	Fri Jun 11 15:15:48 2021 +0000
+++ b/src/njs_regexp.c	Fri Jun 11 15:47:37 2021 +0000
@@ -1828,7 +1828,8 @@ njs_regexp_prototype_symbol_split(njs_vm
     end = &s.start[s.size];
 
     if (utf8 == NJS_STRING_UTF8) {
-        start = njs_string_offset(s.start, s.start + s.size, p);
+        start = (p < length) ? njs_string_offset(s.start, s.start + s.size, p)
+                             : end;
 
     } else {
         start = &s.start[p];
diff -r 1c066436ec55 -r a0f5719c8d9a src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c	Fri Jun 11 15:15:48 2021 +0000
+++ b/src/test/njs_unit_test.c	Fri Jun 11 15:47:37 2021 +0000
@@ -8861,6 +8861,9 @@ static njs_unit_test_t  njs_test[] =
     { njs_str("'abc'.split(/abc/)"),
       njs_str(",") },
 
+    { njs_str("('α'.repeat(32)).split(/./).length"),
+      njs_str("33") },
+
     { njs_str("'AbcDefGhi'.split(/([A-Z][a-z]+)/)"),
       njs_str(",Abc,,Def,,Ghi,") },
 


More information about the nginx-devel mailing list