Commit e448fbf
Fix integer overflow in Chakra napi_create_dataview bounds check
napi_create_dataview validated the requested view with an unchecked
�yte_length + byte_offset > bufferLength comparison. byte_length and
byte_offset are caller-supplied size_t values, so on 64-bit builds their sum
can overflow and wrap past the limit. When that happens the values are then
truncated to 32-bit for JsCreateDataView (creating a small, valid view) while
the ORIGINAL 64-bit values are stored in DataViewInfo and later returned by
napi_get_dataview_info alongside the small backing buffer, giving a calling
addon an out-of-bounds read/write primitive.
Validate byte_offset and byte_length against the buffer size individually
without adding them, so neither overflow nor the subsequent 32-bit truncation
can slip an out-of-range view past the check. After the check both values are
<= bufferLength (a 32-bit quantity), so the truncation and the stored values
are guaranteed in range.
The JavaScriptCore backend delegates to the JS DataView constructor and is
unaffected. The V8 backend carries the same upstream pattern but is vendored
verbatim from Node and left untouched.
Add a native regression test (the path is not reachable from JS
ew DataView)
that crafts an offset/length whose low 32 bits are valid but whose 64-bit sum
wraps, and asserts the view is rejected (or at least never reports the raw
64-bit extents). Guarded to the Chakra engine and 64-bit builds.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent a128e68 commit e448fbf
3 files changed
Lines changed: 82 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2244 | 2244 | | |
2245 | 2245 | | |
2246 | 2246 | | |
2247 | | - | |
| 2247 | + | |
| 2248 | + | |
| 2249 | + | |
| 2250 | + | |
| 2251 | + | |
| 2252 | + | |
| 2253 | + | |
2248 | 2254 | | |
2249 | 2255 | | |
2250 | 2256 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
49 | 53 | | |
50 | 54 | | |
51 | 55 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
274 | 275 | | |
275 | 276 | | |
276 | 277 | | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
277 | 348 | | |
278 | 349 | | |
279 | 350 | | |
| |||
0 commit comments