Skip to content

Commit d681f20

Browse files
author
Robert Fancsik
authored
Fix invalid assertion CESU8-UTF8 buffer copy (#4946)
The UTF8 buffer size can be smaller then the CESU8 string's size so the UTF8 output is may truncated. Therefore we cannot ensure that the CESU8 buffer is read until the end. This patch fixes #4920. JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
1 parent 85bad33 commit d681f20

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

jerry-core/lit/lit-strings.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ lit_convert_cesu8_string_to_utf8_string (const lit_utf8_byte_t *cesu8_string_p,
865865
cesu8_cursor_p += read_size;
866866
}
867867

868-
JERRY_ASSERT (cesu8_cursor_p == cesu8_end_p);
868+
JERRY_ASSERT (cesu8_cursor_p <= cesu8_end_p);
869869
JERRY_ASSERT (utf8_cursor_p <= utf8_end_p);
870870

871871
return (lit_utf8_byte_t) (utf8_cursor_p - utf8_string_p);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
const v2 = String.fromCodePoint(1337);
16+
const v4 = v2.padEnd(1337, v2);
17+
const v7 = undefined[v4];

0 commit comments

Comments
 (0)