Commit 521f429
fix: FlatVector::resizeValues can lose existing values for opaque types (facebookincubator#15487)
Summary:
Pull Request resolved: facebookincubator#15487
There is a bug in FlatVector::resizeValues where for non-POD types (I think this is just opaque
types) if the Buffer is immutable, there's a typo where it copies values from the new Buffer
into itself, losing the existing values.
Fixing this bug exposes another bug that FlatVector::resizeValues uses BaseVector::length_
as the previous size, however, by this point BaseVector::resize has already been invoked, so it
should be equal to new size (leading to reading off the end of the Buffer after the fix for the
first issue).
To address this I pass the previous size to FlatVector::resizeValues as relying on the order of
invoking this function and BaseVector::resize seems error prone.
Another option would be to rely on the Buffer sizes, but then we may be copying more values
than necessary. Along these lines I updated the logic for POD types (other types) to use the
Vector size to determine how many values to copy over (any other values would have been set
to initialValue already if one is needed).
I noticed a similar bug in the bool template specialization of FlatVector::resizeValues where it
was using BaseVector::length_ for deciding how many values to set to initialValue if we are
just updating the size of an existing Buffer with sufficient capacity. I opted to just delete this
code since it is in a private function and there is no invocation that passes an initialValue for a
bool, and it's inconsistent with the base implementation of FlatVector::resizeValues which only
sets values to initialValue if the Buffer is reallocated.
Reviewed By: bikramSingh91
Differential Revision: D86920858
fbshipit-source-id: 83bd8bdc121cc7998f94b412191dfba1e0c745131 parent 646ea2a commit 521f429
File tree
3 files changed
+17
-18
lines changed- velox/vector
- tests
3 files changed
+17
-18
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
456 | 456 | | |
457 | 457 | | |
458 | 458 | | |
459 | | - | |
| 459 | + | |
460 | 460 | | |
461 | 461 | | |
462 | 462 | | |
| |||
476 | 476 | | |
477 | 477 | | |
478 | 478 | | |
479 | | - | |
| 479 | + | |
480 | 480 | | |
481 | 481 | | |
482 | 482 | | |
| |||
537 | 537 | | |
538 | 538 | | |
539 | 539 | | |
| 540 | + | |
540 | 541 | | |
541 | 542 | | |
542 | 543 | | |
| |||
554 | 555 | | |
555 | 556 | | |
556 | 557 | | |
| 558 | + | |
| 559 | + | |
557 | 560 | | |
558 | 561 | | |
559 | 562 | | |
560 | | - | |
561 | | - | |
| 563 | + | |
| 564 | + | |
562 | 565 | | |
563 | | - | |
564 | | - | |
| 566 | + | |
565 | 567 | | |
566 | | - | |
567 | 568 | | |
568 | 569 | | |
569 | 570 | | |
| |||
576 | 577 | | |
577 | 578 | | |
578 | 579 | | |
| 580 | + | |
579 | 581 | | |
580 | 582 | | |
581 | 583 | | |
| |||
586 | 588 | | |
587 | 589 | | |
588 | 590 | | |
589 | | - | |
590 | | - | |
591 | | - | |
592 | | - | |
593 | | - | |
594 | | - | |
595 | | - | |
596 | 591 | | |
597 | 592 | | |
598 | 593 | | |
| |||
602 | 597 | | |
603 | 598 | | |
604 | 599 | | |
605 | | - | |
| 600 | + | |
606 | 601 | | |
607 | 602 | | |
608 | 603 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
574 | 574 | | |
575 | 575 | | |
576 | 576 | | |
577 | | - | |
578 | | - | |
| 577 | + | |
| 578 | + | |
579 | 579 | | |
580 | 580 | | |
| 581 | + | |
581 | 582 | | |
582 | 583 | | |
583 | 584 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
749 | 749 | | |
750 | 750 | | |
751 | 751 | | |
| 752 | + | |
752 | 753 | | |
753 | 754 | | |
| 755 | + | |
| 756 | + | |
754 | 757 | | |
755 | 758 | | |
756 | 759 | | |
757 | 760 | | |
758 | 761 | | |
759 | | - | |
| 762 | + | |
760 | 763 | | |
761 | 764 | | |
762 | 765 | | |
| |||
0 commit comments