From 9893a0eaea81e1411a04534fab8134716a4f59e5 Mon Sep 17 00:00:00 2001 From: Laytan Date: Mon, 3 Nov 2025 20:33:17 +0100 Subject: [PATCH] encoding/cbor: fix epoch tag with small values --- core/encoding/cbor/tags.odin | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/core/encoding/cbor/tags.odin b/core/encoding/cbor/tags.odin index be07b926a..fa456673d 100644 --- a/core/encoding/cbor/tags.odin +++ b/core/encoding/cbor/tags.odin @@ -130,9 +130,9 @@ tag_time_unmarshal :: proc(_: ^Tag_Implementation, d: Decoder, _: Tag_Number, v: case .U8, .U16, .U32, .U64, .Neg_U8, .Neg_U16, .Neg_U32, .Neg_U64: switch &dst in v { case time.Time: - i: i64 - _unmarshal_any_ptr(d, &i, hdr) or_return - dst = time.unix(i64(i), 0) + secs: i64 + _unmarshal_any_ptr(d, &secs, hdr) or_return + dst = time.unix(i64(secs), 0) return case: return _unmarshal_value(d, v, hdr) @@ -152,19 +152,23 @@ tag_time_unmarshal :: proc(_: ^Tag_Implementation, d: Decoder, _: Tag_Number, v: case: maj, add := _header_split(hdr) - if maj == .Other { - i := _decode_tiny_u8(add) or_return - - switch &dst in v { - case time.Time: - dst = time.unix(i64(i), 0) - case: - if _assign_int(v, i) { return } - } + secs: u8 + #partial switch maj { + case .Unsigned: + secs = _decode_tiny_u8(add) or_return + case .Other: + secs = u8(_decode_tiny_simple(add) or_return) + case: + return .Bad_Tag_Value } - // Only numbers and floats are allowed in this tag. - return .Bad_Tag_Value + switch &dst in v { + case time.Time: + dst = time.unix(i64(secs), 0) + return + case: + if _assign_int(v, secs) { return } + } } return _unsupported(v, hdr)