don't die if blksize is too large; clamp it to max allowed.

This commit is contained in:
Sudhi Herle 2020-01-23 12:24:27 +05:30
parent fbfcd37679
commit 0ba5c8b599

View file

@ -79,13 +79,15 @@ type Encryptor struct {
// signing any recipient keys. If 'sk' is nil, then ephmeral Curve25519 keys // signing any recipient keys. If 'sk' is nil, then ephmeral Curve25519 keys
// are generated and used with recipient's public key. // are generated and used with recipient's public key.
func NewEncryptor(sk *PrivateKey, blksize uint64) (*Encryptor, error) { func NewEncryptor(sk *PrivateKey, blksize uint64) (*Encryptor, error) {
if blksize >= uint64(maxChunkSize) { var blksz uint32
return nil, fmt.Errorf("encrypt: Blocksize is too large (max 16M)")
}
blksz := uint32(blksize) switch {
if blksz == 0 { case blksize == 0:
blksz = chunkSize blksz = chunkSize
case blksize > uint64(maxChunkSize):
blksz = maxChunkSize
default:
blksz = uint32(blksize)
} }
e := &Encryptor{ e := &Encryptor{