Commit 7800803
fix: fastbufferreader string deserialization int overflow (#4052)
* fix
This fixes an edge case scenario with string reading where if user code has caused the character count to have been already read prior to attempting to read a string value (safely or unsafely) and then reading the string can result in the signed integer size to roll over to a negative value and thus causing the reader to attempt to read into restricted memory outside of the application domain which results in the editor crashing.
The fix catches this scenario and throws an overflow exception prior to attempting to read into negative memory space relative to the application domain.
* test
This test validates the fix.
* update
Adding changelog entry.
* update
Making the reader use the already calculated readSize.
* test
Updating test to unsafely read a string under the same condition.
* fix
Fixing an issue where the unsafe string read needs to create an empty string based on the character count and not the byte count.
* refactor
Based on Paolo's suggestion on combining the string size, in bytes, validation script to a single in-lined method shared between the safe and unsafe string read methods.
Also combined the actual reading of the string data into a single in-lined method.
* style
Removing the auto-added (and not used) UnityEngine.UIElements using directive.
* style
updated comments and renamed CheckIfValidStringLength to ValidateStringByteCount.
* test
Removing the added 3 bytes used for earlier debugging purposes.
* style
spelling/typo fix.
whitespace after sentence in comment fix.
* refactor
Based on Emma's suggestion, removing the `SizeOfLengthField` method and `TryBeginReadInternal` check within the ReadValueSafe (string) method and replacing that with `ReadLengthSafe`.
* Update com.unity.netcode.gameobjects/Runtime/Serialization/FastBufferReader.cs
Co-authored-by: Emma <emma.mcmillan@unity3d.com>
* update
Based on suggestion from Emma, removing InBitwiseContext check since this is done in both ReadLengthSafe and TryBeginReadInternal.
---------
Co-authored-by: Emma <emma.mcmillan@unity3d.com>1 parent e6ecb65 commit 7800803
3 files changed
Lines changed: 108 additions & 46 deletions
File tree
- com.unity.netcode.gameobjects
- Runtime/Serialization
- Tests/Editor/Serialization
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
| 25 | + | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
| |||
Lines changed: 62 additions & 46 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
564 | 564 | | |
565 | 565 | | |
566 | 566 | | |
567 | | - | |
568 | | - | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
569 | 590 | | |
570 | | - | |
571 | | - | |
572 | | - | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
573 | 596 | | |
574 | | - | |
575 | 597 | | |
576 | 598 | | |
577 | 599 | | |
| |||
592 | 614 | | |
593 | 615 | | |
594 | 616 | | |
595 | | - | |
596 | | - | |
597 | | - | |
598 | | - | |
599 | | - | |
| 617 | + | |
| 618 | + | |
600 | 619 | | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
601 | 624 | | |
602 | | - | |
603 | | - | |
| 625 | + | |
| 626 | + | |
604 | 627 | | |
605 | | - | |
606 | | - | |
607 | | - | |
608 | | - | |
609 | | - | |
610 | | - | |
611 | | - | |
| 628 | + | |
612 | 629 | | |
613 | | - | |
614 | | - | |
615 | | - | |
616 | | - | |
| 630 | + | |
| 631 | + | |
617 | 632 | | |
618 | | - | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
619 | 650 | | |
620 | | - | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
621 | 654 | | |
622 | 655 | | |
623 | 656 | | |
624 | | - | |
625 | | - | |
626 | | - | |
627 | | - | |
628 | | - | |
629 | | - | |
630 | | - | |
631 | | - | |
632 | | - | |
633 | | - | |
634 | | - | |
635 | | - | |
636 | | - | |
637 | | - | |
638 | | - | |
639 | | - | |
640 | | - | |
641 | | - | |
642 | 657 | | |
643 | | - | |
644 | | - | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
645 | 661 | | |
646 | 662 | | |
647 | 663 | | |
| |||
Lines changed: 44 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
924 | 924 | | |
925 | 925 | | |
926 | 926 | | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
927 | 971 | | |
928 | 972 | | |
929 | 973 | | |
| |||
0 commit comments