Commit 82e5acf
committed
fix(cable): bound decrypt_frame indexing on malformed Noise plaintext
After Noise transport decryption, the last byte of the plaintext is
read as a 0..=255 padding length and the frame is truncated by
`padding_len + 1`. Two crash inputs are reachable from any
legitimate-but-malicious paired peer:
1. Empty plaintext (Noise transport accepts a 16-byte AEAD-tag-only
ciphertext, decrypting to 0 bytes): reading `frame[len - 1]`
underflows to `usize::MAX` and panics with `index out of bounds`.
2. Under-padded plaintext (e.g., `[0x05]`): `1 - 6` panics in debug
builds and silently wraps in release, so the subsequent
`truncate(huge)` no-ops and the malformed plaintext is parsed
downstream.
Extract the padding-stripping into a `strip_frame_padding` helper that
uses `.last()` and `.checked_sub`, returning
`Error::Transport(TransportError::InvalidFraming)` on either edge
case. Add regression tests for the empty and overlong-padding inputs
plus a happy-path check.1 parent 10ee804 commit 82e5acf
1 file changed
Lines changed: 54 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
523 | 523 | | |
524 | 524 | | |
525 | 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 | + | |
526 | 551 | | |
527 | 552 | | |
528 | 553 | | |
| |||
543 | 568 | | |
544 | 569 | | |
545 | 570 | | |
546 | | - | |
547 | | - | |
| 571 | + | |
548 | 572 | | |
549 | 573 | | |
550 | 574 | | |
| |||
795 | 819 | | |
796 | 820 | | |
797 | 821 | | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
798 | 850 | | |
0 commit comments