Skip to content

Commit 65e81f3

Browse files
Daniel Ballarerobika
authored andcommitted
Fix UTF8 string length calculation (#2508)
Fixes #2451 Fixes #2452 Fixes #2453 Co-authored-by: Robert Fancsik <[email protected]> JerryScript-DCO-1.0-Signed-off-by: Daniel Balla [email protected]
1 parent b934dd8 commit 65e81f3

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed

jerry-core/ecma/base/ecma-helpers-string.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2052,7 +2052,7 @@ ecma_string_get_utf8_length (const ecma_string_t *string_p) /**< ecma-string */
20522052
return (ecma_length_t) (long_string_p->long_utf8_string_length);
20532053
}
20542054

2055-
return lit_get_utf8_length_of_cesu8_string ((const lit_utf8_byte_t *) (string_p + 1),
2055+
return lit_get_utf8_length_of_cesu8_string ((const lit_utf8_byte_t *) (long_string_p + 1),
20562056
(lit_utf8_size_t) string_p->u.long_utf8_string_size);
20572057
}
20582058
default:
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright JS Foundation and other contributors, http://js.foundation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
var src = "var a = 0; while(a) { switch(a) {" ;
16+
for (var i = 0; i < 4000; i++)
17+
src += "-Infinity" + i + "\u00a0\u00a01.2e3";
18+
src += "\udc00%f0%90%80%80\udc00";
19+
print(src);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright JS Foundation and other contributors, http://js.foundation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
var src = "";
16+
for (var i = 0; i < 4000; i++)
17+
src += "\udc00%f0%90%80%80\udc00";
18+
src += "} }";
19+
print(src);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright JS Foundation and other contributors, http://js.foundation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
var src = "";
16+
for (var i = 0; i < 4000; i++)
17+
src += 4 + i + ": a += a += a; break; ";
18+
src += "\𝔺\
19+
\
";
20+
print(src);

0 commit comments

Comments
 (0)