]> Cypherpunks repositories - keks.git/commitdiff
Fixed TAI64N[A] *seconds validation
authorSergey Matveev <stargrave@stargrave.org>
Thu, 21 Nov 2024 09:03:28 +0000 (12:03 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Thu, 21 Nov 2024 09:03:28 +0000 (12:03 +0300)
cyac/lib/dec.c
cyac/lib/err.c
cyac/lib/err.h
gyac/dec.go
pyac/pyac.py

index ad1c776d85baa5041a42ee28d4a1b5eedebcf6324bfccf3b277c525ee07478dd..2bdc73947d74d0260183d6dd5411fdedb5aba97af21212ddc97b2952dec9ca8c 100644 (file)
@@ -241,21 +241,23 @@ YACAtomDecode( // NOLINT(misc-no-recursion)
         if (v > ((uint64_t)1 << (uint8_t)63)) {
             return YACErrTAI64TooBig;
         }
-        switch (l) {
-        case 12:
+        if (l > 8) {
             v = yacFromBE(buf + 1 + 8, 4);
+            if ((l == 8) && (v == 0)) {
+                return YACErrTAI64NonMinimal;
+            }
             if (v > 999999999) {
                 return YACErrTAI64BadNsec;
             }
-            break;
-        case 16:
+        }
+        if (l > 12) {
             v = yacFromBE(buf + 1 + 8 + 4, 4);
+            if (v == 0) {
+                return YACErrTAI64NonMinimal;
+            }
             if (v > 999999999) {
                 return YACErrTAI64BadAsec;
             }
-            break;
-        default:
-            break;
         }
         break;
     }
index c95194286c967d17e0a0f03f849707daefd337fa2c5f7ad1755cc9a8637eb934..2eb870bb2e32e454c5447d897b72d63f7b0688d92347d0abffbbd7f52f35c217 100644 (file)
@@ -34,6 +34,8 @@ YACErr2Str(const enum YACErr err)
         return "TAI64InPast";
     case YACErrTAI64IsLeap:
         return "TAI64IsLeap";
+    case YACErrTAI64NonMinimal:
+        return "TAI64NonMinimal";
     case YACErrMapBadKey:
         return "MapBadKey";
     case YACErrMapNoVal:
index 00726a68ee584efecb600c2202dc8531331999e014a7b11d52ed92240aa15dbc..55898d764e9e208904c81d61e67a9263f9552efcb9fae4976056c86b615bf327 100644 (file)
@@ -57,6 +57,7 @@ enum YACErr {
     YACErrTAI64BadAsec,
     YACErrTAI64InPast,
     YACErrTAI64IsLeap,
+    YACErrTAI64NonMinimal,
     YACErrMapBadKey,
     YACErrMapNoVal,
     YACErrMapUnordered,
index 17ba262d532c63396ff2c2834865b756a86fbc0c89027dc79ca525f48424c1a2..7c4d82502bee2b4ee18c008024a0f01da113884c1295327f1b9c30b6a3ab834a 100644 (file)
@@ -281,14 +281,24 @@ func AtomDecode(buf []byte) (item *Item, off int, err error) {
                        err = errors.New("reserved TAI64 values in use")
                        return
                }
-               switch l {
-               case 12:
-                       if FromBE(buf[1+8:1+8+4]) > 999999999 {
+               if l > 8 {
+                       nsecs := FromBE(buf[1+8 : 1+8+4])
+                       if l == 8 && nsecs == 0 {
+                               err = errors.New("non-minimal TAI64N")
+                               return
+                       }
+                       if nsecs > 999999999 {
                                err = errors.New("too many nanoseconds")
                                return
                        }
-               case 16:
-                       if FromBE(buf[1+8+4:1+8+4+4]) > 999999999 {
+               }
+               if l > 12 {
+                       asecs := FromBE(buf[1+8+4 : 1+8+4+4])
+                       if asecs == 0 {
+                               err = errors.New("non-minimal TAI64NA")
+                               return
+                       }
+                       if asecs > 999999999 {
                                err = errors.New("too many attoseconds")
                                return
                        }
index dbdcc69e74966e4347d932ac8364c374f5c2e56cc04f2619d4b0dd2874f03f95..bac693ccf2f1cff4a12ee73d0533e7428986ccf2bdbc85e858c3c67939e6c3ff 100755 (executable)
@@ -299,14 +299,14 @@ def loads(v, sets=False, leapsecUTCAllow=False):
         if l > 8:
             nsecs = int.from_bytes(v[1+8:1+8+4], "big")
             if (l == 8) and (nsecs == 0):
-                raise DecodeError("non-minimal encoding")
+                raise DecodeError("non-minimal TAI64N")
             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")
+                raise DecodeError("non-minimal TAI64NA")
             if asecs > 999999999:
                 raise DecodeError("too many attoseconds")
         secs = tai2utc(secs - TAI64Base, leapsecUTCAllow)