Commit 4a9feca
committed
buffer: fix silent data corruption with indices >= 2^32
SlowCopy and FastCopy in node_buffer.cc used uint32_t for target_start,
source_start, and to_copy parameters. When these values exceeded 2^32,
they silently wrapped around, causing Buffer.copy and Buffer.concat to
produce incorrect results with large buffers.
Change CopyImpl parameters from uint32_t to size_t, SlowCopy to use
IntegerValue (int64_t) instead of Uint32, and FastCopy to use uint64_t.
Add a guard against negative int64_t values before casting to size_t
to prevent potential out-of-bounds access.
Note: other functions in node_buffer.cc (CopyArrayBuffer, StringWrite,
FastByteLengthUtf8) have similar uint32_t limitations but are not
addressed here to keep this change focused on the reported regression.
Fixes: #554221 parent 5b5f069 commit 4a9feca
2 files changed
+84
-13
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
587 | 587 | | |
588 | 588 | | |
589 | 589 | | |
590 | | - | |
591 | | - | |
592 | | - | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
593 | 593 | | |
594 | 594 | | |
595 | 595 | | |
| |||
598 | 598 | | |
599 | 599 | | |
600 | 600 | | |
| 601 | + | |
601 | 602 | | |
602 | 603 | | |
603 | | - | |
604 | | - | |
605 | | - | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
606 | 615 | | |
607 | | - | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
608 | 621 | | |
609 | | - | |
| 622 | + | |
610 | 623 | | |
611 | 624 | | |
612 | 625 | | |
613 | | - | |
| 626 | + | |
614 | 627 | | |
615 | 628 | | |
616 | | - | |
617 | | - | |
618 | | - | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
619 | 632 | | |
620 | 633 | | |
621 | 634 | | |
622 | 635 | | |
623 | | - | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
624 | 641 | | |
625 | 642 | | |
626 | 643 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
0 commit comments