Skip to content

Validate buffer sizes and overlap in Encrypt/Decrypt - #5

Merged
schultz-is merged 1 commit into
trunkfrom
fix/encrypt-decrypt-validation
Aug 3, 2026
Merged

Validate buffer sizes and overlap in Encrypt/Decrypt#5
schultz-is merged 1 commit into
trunkfrom
fix/encrypt-decrypt-validation

Conversation

@schultz-is

Copy link
Copy Markdown
Owner

The block methods indexed src/dst directly with no bounds or overlap checks, so a short buffer produced an opaque "slice bounds out of range" panic and invalid partial overlap went undetected. Follow the standard-library crypto/cipher.Block convention (as in crypto/aes and crypto/des): panic with clear messages when the input or output is not a full block, and reject inexact buffer overlap.

Add an unexported inexactOverlap helper copied from the stdlibs crypto/internal/fips140/alias (not importable externally; also present in golang.org/x/crypto/internal/alias). Exact overlap (in-place operation) remains allowed, matching the existing in-place Decrypt usage.

Add TestThreefish{256,512,1024}Panics covering short input, short output, and inexact overlap for both Encrypt and Decrypt, plus a check that in-place operation does not panic.

The block methods indexed src/dst directly with no bounds or overlap checks, so
a short buffer produced an opaque "slice bounds out of range" panic and invalid
partial overlap went undetected. Follow the standard-library crypto/cipher.Block
convention (as in crypto/aes and crypto/des): panic with clear messages when the
input or output is not a full block, and reject inexact buffer overlap.

Add an unexported inexactOverlap helper copied from the stdlibs
crypto/internal/fips140/alias (not importable externally; also present in
golang.org/x/crypto/internal/alias). Exact overlap (in-place operation) remains
allowed, matching the existing in-place Decrypt usage.

Add TestThreefish{256,512,1024}Panics covering short input, short output, and
inexact overlap for both Encrypt and Decrypt, plus a check that in-place
operation does not panic.
@schultz-is
schultz-is merged commit c3c8e50 into trunk Aug 3, 2026
5 checks passed
@schultz-is
schultz-is deleted the fix/encrypt-decrypt-validation branch August 3, 2026 01:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant