Repository navigation
Commit 4b00d36
committed
Validate snapshot offsets before reading the compiled code
jerry_exec_snapshot() trusted the offsets stored in the snapshot header
and in the bytecode it deserializes:
* func_offsets[func_index] was used directly to locate the compiled
code, and its status_flags field was read without checking that the
offset was inside the snapshot;
* the size field of the compiled code header was used as the block
size, so a block could claim to extend beyond the input buffer and
the argument-header writes and literal loops below would touch
memory outside it;
* the literal offsets in the literal table were used the same way when
recursively loading a nested function.
A short malformed snapshot (73 bytes in the report) therefore made the
engine read and write outside the buffer:
==ERROR: AddressSanitizer: SEGV
#0 jerry_exec_snapshot jerry-snapshot.c:915
Check the fixed header size, the declared block size and the literal
offsets against the end of the snapshot before any of them is used, and
propagate the buffer bounds into snapshot_load_compiled_code() for the
recursive case. Malformed input now returns a normal exception instead
of dereferencing out-of-bounds memory.
Adds a regression case to tests/unit-core/test-snapshot.c.
JerryScript-DCO-1.0-Signed-off-by: 1820893135-pixel <1820893135@qq.com>1 parent b706935 commit 4b00d36
2 files changed
Lines changed: 98 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
542 | 542 | | |
543 | 543 | | |
544 | 544 | | |
545 | | - | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
546 | 548 | | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
547 | 558 | | |
548 | 559 | | |
549 | 560 | | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
550 | 571 | | |
551 | 572 | | |
552 | 573 | | |
| |||
698 | 719 | | |
699 | 720 | | |
700 | 721 | | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
701 | 730 | | |
702 | | - | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
703 | 738 | | |
704 | 739 | | |
705 | 740 | | |
| |||
910 | 945 | | |
911 | 946 | | |
912 | 947 | | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
913 | 958 | | |
914 | 959 | | |
915 | 960 | | |
| |||
971 | 1016 | | |
972 | 1017 | | |
973 | 1018 | | |
974 | | - | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
975 | 1022 | | |
976 | 1023 | | |
977 | 1024 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
26 | 38 | | |
27 | 39 | | |
28 | 40 | | |
| |||
436 | 448 | | |
437 | 449 | | |
438 | 450 | | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
439 | 485 | | |
440 | 486 | | |
441 | 487 | | |
442 | 488 | | |
443 | 489 | | |
| 490 | + | |
| 491 | + | |
444 | 492 | | |
445 | 493 | | |
446 | 494 | | |
| |||
0 commit comments