Commit 8f16aba
committed
numpy_parser: reject undersized vector payloads too, add test coverage
The memcpy fast-path guard in unpack_row() only rejected oversized
payloads (buf.size > arr.stride), which prevents the buffer-overflow
case but let undersized payloads slip through, leaving the remainder
of the row filled with uninitialized/stale heap bytes instead of
raising. Tighten the check to buf.size != arr.stride so both
directions are rejected, and update the error message accordingly,
including the column name for easier debugging.
Add tests covering both the oversized and undersized payload cases,
since neither had test coverage before.
Also revert the arrays = [] / .append() -> [None]*n / index-assign
change in make_arrays(), which was functionally identical diff noise
unrelated to the VectorType/2D-array feature.
Restore ShortType (smallint) to _cqltype_to_numpy: an earlier fix on
this PR removed it from that table entirely to stop the VectorType
fast-path from assuming a fixed 2-byte stride for vint-prefixed vector
elements, but the table is shared with the plain scalar top-level
column dispatch in make_array(), where smallint genuinely *is*
fixed-width (no length prefix). Removing the entry regressed scalar
smallint columns onto the slow object-array fallback. Fix: keep
ShortType in the shared table, and instead guard the VectorType.subtype
call site with `subtype.serial_size() is not None` (the same check
VectorType.serialize()/deserialize() use) before consulting the table,
so only the vector-specific dispatch excludes non-fixed-width subtypes.
This also protects any subtype added to the table in the future.
Add tests for the restored scalar smallint fast path (both make_array()
directly and an end-to-end parse_rows() round-trip).
Also fix tests/unit/test_numpy_parser.py's HAVE_NUMPY gating: a bare
`except ImportError` around the numpy_parser/bytesio/etc. imports
could not distinguish "numpy genuinely not installed" from "the
numpy_parser Cython extension is broken despite numpy being present",
silently skipping the whole test module in both cases. Gate instead on
cassandra.cython_deps.HAVE_CYTHON and HAVE_NUMPY (plus the
VERIFY_CYTHON override), matching the `numpytest` convention in
tests/unit/cython/utils.py, and import unconditionally once those are
satisfied so a broken extension surfaces as a real test failure.1 parent 349014d commit 8f16aba
2 files changed
Lines changed: 216 additions & 28 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| 70 | + | |
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
84 | 105 | | |
85 | 106 | | |
86 | 107 | | |
| |||
123 | 144 | | |
124 | 145 | | |
125 | 146 | | |
126 | | - | |
| 147 | + | |
127 | 148 | | |
128 | 149 | | |
129 | 150 | | |
| |||
136 | 157 | | |
137 | 158 | | |
138 | 159 | | |
139 | | - | |
| 160 | + | |
140 | 161 | | |
141 | 162 | | |
142 | 163 | | |
| |||
151 | 172 | | |
152 | 173 | | |
153 | 174 | | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
161 | 195 | | |
162 | 196 | | |
163 | 197 | | |
| |||
189 | 223 | | |
190 | 224 | | |
191 | 225 | | |
192 | | - | |
| 226 | + | |
193 | 227 | | |
194 | | - | |
195 | | - | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
196 | 231 | | |
197 | 232 | | |
198 | 233 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
18 | 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 | + | |
19 | 46 | | |
20 | 47 | | |
21 | 48 | | |
22 | 49 | | |
23 | 50 | | |
24 | 51 | | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | 52 | | |
30 | 53 | | |
31 | 54 | | |
32 | | - | |
| 55 | + | |
33 | 56 | | |
34 | 57 | | |
35 | 58 | | |
| |||
476 | 499 | | |
477 | 500 | | |
478 | 501 | | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
479 | 568 | | |
480 | 569 | | |
481 | 570 | | |
| |||
533 | 622 | | |
534 | 623 | | |
535 | 624 | | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
536 | 689 | | |
537 | 690 | | |
0 commit comments