padding: fix "Size computation for allocation may overflow"

This commit is contained in:
Sun Yimin 2025-03-19 11:16:26 +08:00 committed by GitHub
parent 93c965f3c1
commit 3cc92436ee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -30,6 +30,11 @@ func (pad iso9797M3Padding) Pad(src []byte) []byte {
var head, tail []byte var head, tail []byte
total := srcLen + overhead + pad.BlockSize() total := srcLen + overhead + pad.BlockSize()
if total <= 0 {
panic("padding: total length overflow")
}
if cap(src) >= total { if cap(src) >= total {
head = src[:total] head = src[:total]
} else { } else {