Skip to content

Commit e04bbdf

Browse files
authored
Fix byteLength validation in DataView constructor (#3074)
This patch fixes #3072. JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
1 parent c79659d commit e04bbdf

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

jerry-core/ecma/operations/ecma-dataview-object.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ ecma_op_dataview_create (const ecma_value_t *arguments_list_p, /**< arguments li
118118
}
119119
else if (ecma_number_is_infinity (byte_length))
120120
{
121+
if (ecma_number_is_negative (byte_length))
122+
{
123+
return ecma_raise_range_error (ECMA_ERR_MSG ("Invalid DataView length"));
124+
}
125+
121126
viewByteLength = UINT32_MAX;
122127
}
123128
else if (byte_length_int32 <= 0)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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 arrb = new ArrayBuffer(13);
16+
17+
try {
18+
var d = new DataView(arrb, 12, -Infinity);
19+
d.setFloat32(1, 1);
20+
assert (false);
21+
} catch (e) {
22+
assert (e instanceof RangeError);
23+
}

0 commit comments

Comments
 (0)