]> Cypherpunks repositories - keks.git/commitdiff
Assure that minimally encoded TAI64s are used
authorSergey Matveev <stargrave@stargrave.org>
Wed, 20 Nov 2024 21:25:26 +0000 (00:25 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Wed, 20 Nov 2024 21:25:26 +0000 (00:25 +0300)
pyac/pyac.py

index 43dcf8b22320eb6794a07fd881276a776d63a014c06fa9e70330c3481a68e89a..92f0ec46224b66b080609e866f4844d6e42c54655726d2609cf46e603fe400cf 100755 (executable)
@@ -298,11 +298,15 @@ def loads(v, sets=False, leapsecUTCAllow=False):
         nsecs = 0
         if l > 8:
             nsecs = int.from_bytes(v[1+8:1+8+4], "big")
+            if nsecs == 0:
+                raise DecodeError("non-minimal encoding")
             if nsecs > 999999999:
                 raise DecodeError("too many nanoseconds")
         asecs = 0
         if l > 12:
             asecs = int.from_bytes(v[1+8+4:1+8+4+4], "big")
+            if asecs == 0:
+                raise DecodeError("non-minimal encoding")
             if asecs > 999999999:
                 raise DecodeError("too many attoseconds")
         secs = tai2utc(secs - TAI64Base, leapsecUTCAllow)