Skip to content

Commit f264c5f

Browse files
committed
Check padding correctness.
1 parent 95ac1c9 commit f264c5f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

main.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,18 @@ func Decrypt(r io.Reader, w io.Writer, password []byte) error {
127127
dec := cipher.NewCBCDecrypter(a, iv)
128128
dec.CryptBlocks(out, content)
129129

130-
// Strip padding.
130+
// Check and strip padding.
131131
n := out[len(out)-1]
132132
if n <= 0 || n > aes.BlockSize {
133133
return ErrCorrupted
134134
}
135+
x := int(n)
136+
for _, v := range out[len(out)-int(n):] {
137+
x -= subtle.ConstantTimeByteEq(v, n)
138+
}
139+
if x != 0 {
140+
return ErrCorrupted
141+
}
135142
out = out[:len(out)-int(n)]
136143

137144
nw, err := w.Write(out)

0 commit comments

Comments
 (0)