padding: fix codeql reported security issue

This commit is contained in:
Sun Yimin 2025-06-23 10:27:45 +08:00 committed by GitHub
parent 59f85b654e
commit 8cfcf01ec3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

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