kstenerud / concise-encoding

The secure data format for a modern world
https://concise-encoding.org
Other
258 stars 4 forks source link

Time zone length limit #22

Closed kengruven closed 3 years ago

kengruven commented 3 years ago

The CE/CTE specs don't say anything about a length limit on a time zone name. In CBE ("Compact Time"), the length field is 7 bits wide, so you get a max of 127 bytes of (UTF-8, I assume) character data.

Right now, if you provide a longer TZ string, enctool is happy to parse it and re-encode it in CBE, but this creates an invalid document that it can't parse:

$ echo 'c1 1985-10-26/01:20:01.105/AaaaaaaaaaAaaaaaaaaaAaaaaaaaaaAaaaaaaaaaAaaaaaaaaaAaaaaaaaaaAaaaaaaaaaAaaaaaaaaaAaaaaaaaaaAaaaaaaaaaAaaaaaaaaaAaaaaaaaaaAaaaaaaaaa' | ./enctool convert -df cbe | hexdump -C
00000000  03 00 9b 4b 23 a0 82 d6  0e 04 41 61 61 61 61 61  |...K#.....Aaaaaa|
00000010  61 61 61 61 41 61 61 61  61 61 61 61 61 61 41 61  |aaaaAaaaaaaaaaAa|
00000020  61 61 61 61 61 61 61 61  41 61 61 61 61 61 61 61  |aaaaaaaaAaaaaaaa|
00000030  61 61 41 61 61 61 61 61  61 61 61 61 41 61 61 61  |aaAaaaaaaaaaAaaa|
00000040  61 61 61 61 61 61 41 61  61 61 61 61 61 61 61 61  |aaaaaaAaaaaaaaaa|
00000050  41 61 61 61 61 61 61 61  61 61 41 61 61 61 61 61  |AaaaaaaaaaAaaaaa|
00000060  61 61 61 61 41 61 61 61  61 61 61 61 61 61 41 61  |aaaaAaaaaaaaaaAa|
00000070  61 61 61 61 61 61 61 61  41 61 61 61 61 61 61 61  |aaaaaaaaAaaaaaaa|
00000080  61 61 41 61 61 61 61 61  61 61 61 61              |aaAaaaaaaaaa|
0000008c

$ echo 'c1 1985-10-26/01:20:01.105/AaaaaaaaaaAaaaaaaaaaAaaaaaaaaaAaaaaaaaaaAaaaaaaaaaAaaaaaaaaaAaaaaaaaaaAaaaaaaaaaAaaaaaaaaaAaaaaaaaaaAaaaaaaaaaAaaaaaaaaaAaaaaaaaaa' | ./enctool convert -df cbe | ./enctool convert -df cte
c0
1985-10-26/01:20:01.105/AaDataTypeInt is not allowed while processing end document

Since this is a fixed-width field in CBE, I think CE should declare that TZ strings can't be longer than 127 bytes (and libraries should enforce that).

kstenerud commented 3 years ago

Good catch! Added https://github.com/kstenerud/concise-encoding/commit/1c775f463c14bf940f9f2da64459b430750c7192 and also the reference implementation, go-compact-time, and enctool are updated.

kengruven commented 3 years ago

I've confirmed that it now works for len=127, and aborts for len=128. Thanks.