crypto: fix pkcs7 padding check

related: ricmoo/pyaes#22

in practice, the only strings we would incorrectly accept are
(certain length of) all zero bytes
This commit is contained in:
SomberNight 2018-11-22 18:21:19 +01:00
parent a8e6eaa247
commit f04e5fbed6
No known key found for this signature in database
GPG key ID: B33B5F232C6271E9

View file

@ -55,8 +55,8 @@ def strip_PKCS7_padding(data: bytes) -> bytes:
if len(data) % 16 != 0 or len(data) == 0:
raise InvalidPadding("invalid length")
padlen = data[-1]
if padlen > 16:
raise InvalidPadding("invalid padding byte (large)")
if not (0 < padlen <= 16):
raise InvalidPadding("invalid padding byte (out of range)")
for i in data[-padlen:]:
if i != padlen:
raise InvalidPadding("invalid padding byte (inconsistent)")