Commit 911e40d
committed
fix: Add buffer bounds validation to Cython deserializers
Add bounds checking to prevent buffer overruns and properly
handle CQL protocol value semantics in deserializers.
Changes:
- subelem(): Add bounds validation with protocol-compliant value handling
* Happy path: Check elemlen >= 0 and offset + elemlen <= buf.size
* Support NULL values (elemlen == -1) per CQL protocol
* Support "not set" values (elemlen == -2) per CQL protocol
* Reject invalid values (elemlen < -2) with clear error message
- _unpack_len(): Add bounds check before reading int32 length field
* Validates offset + 4 <= buf.size before pointer dereference
* Prevents reading beyond buffer boundaries
- DesTupleType: Add defensive bounds checking for tuple deserialization
* Check p + 4 <= buf.size before reading item length
* Check p + itemlen <= buf.size before reading item data
* Explicit NULL value handling (itemlen < 0)
* Clear error messages for buffer overruns
- DesCompositeType: Add bounds validation for composite type elements
* Check 2 + element_length + 1 <= buf.size (length + data + EOC byte)
* Prevents buffer overrun when reading composite elements
- DesVectorType._deserialize_generic(): Add size validation
* Verify buf.size == expected_size before processing
* Provides clear error message with expected vs actual sizes
Protocol specification reference:
[value] = [int] n, followed by n bytes if n >= 0
n == -1: NULL value
n == -2: not set value
n < -2: invalid (error)
Signed-off-by: Yaniv Kaul <yaniv.kaul@scylladb.com>1 parent 7451f9f commit 911e40d
1 file changed
Lines changed: 54 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
398 | 398 | | |
399 | 399 | | |
400 | 400 | | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
401 | 408 | | |
402 | 409 | | |
403 | 410 | | |
| |||
473 | 480 | | |
474 | 481 | | |
475 | 482 | | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
476 | 488 | | |
477 | 489 | | |
478 | 490 | | |
479 | 491 | | |
480 | 492 | | |
481 | | - | |
482 | | - | |
483 | | - | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
484 | 508 | | |
485 | 509 | | |
486 | 510 | | |
487 | 511 | | |
| 512 | + | |
| 513 | + | |
488 | 514 | | |
489 | 515 | | |
490 | 516 | | |
| |||
556 | 582 | | |
557 | 583 | | |
558 | 584 | | |
559 | | - | |
| 585 | + | |
560 | 586 | | |
561 | 587 | | |
562 | 588 | | |
563 | | - | |
| 589 | + | |
| 590 | + | |
564 | 591 | | |
565 | 592 | | |
566 | 593 | | |
567 | 594 | | |
568 | 595 | | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
569 | 603 | | |
570 | 604 | | |
571 | 605 | | |
| |||
607 | 641 | | |
608 | 642 | | |
609 | 643 | | |
610 | | - | |
611 | 644 | | |
612 | | - | |
613 | | - | |
614 | | - | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
615 | 652 | | |
616 | | - | |
617 | | - | |
618 | | - | |
619 | | - | |
620 | | - | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
621 | 661 | | |
622 | 662 | | |
623 | 663 | | |
| |||
0 commit comments