From: Sergey Matveev Date: Sun, 13 Oct 2024 16:26:19 +0000 (+0300) Subject: Forbid empty map strings X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=c68e0ce1b41d511332bcbc4e83fbe27bdb6190516f154c68787704fe4d1a573b;p=keks.git Forbid empty map strings --- diff --git a/cyac/cmd/print.c b/cyac/cmd/print.c index 1a8b607..9302717 100644 --- a/cyac/cmd/print.c +++ b/cyac/cmd/print.c @@ -246,7 +246,7 @@ main(int argc, char **argv) ptrdiff_t off = 0; enum YACErr err = YACAtomDecode(&atom, buf, len); if (err != YACErrNo) { - fprintf(stderr, "map err: %d\n", err); + fprintf(stderr, "err: %d\n", err); return EXIT_FAILURE; } off += atom.off; diff --git a/cyac/iter.c b/cyac/iter.c index 9d81045..6724aa2 100644 --- a/cyac/iter.c +++ b/cyac/iter.c @@ -77,6 +77,9 @@ YACIterMap( if (atom->typ != YACItemStr) { return YACErrMapBadKey; } + if (atom->len == 0) { + return YACErrMapBadKey; + } if (atom->len < keyLen) { return YACErrMapUnordered; } diff --git a/gyac/dec.go b/gyac/dec.go index 8f41f71..5bc7a92 100644 --- a/gyac/dec.go +++ b/gyac/dec.go @@ -334,6 +334,10 @@ func DecodeItem(buf []byte) (item *Item, tail []byte, err error) { } { s := sub.V.(string) + if len(s) == 0 { + err = ErrMapBadKey + return + } if len(s) < len(keyPrev) { err = ErrMapUnordered return diff --git a/pyac/pyac.py b/pyac/pyac.py index 64c7fdd..c419ee5 100644 --- a/pyac/pyac.py +++ b/pyac/pyac.py @@ -267,6 +267,8 @@ class Map: if not isinstance(k, Str): raise DecodeError("non-string key") k = str(k) + if len(k) == 0: + raise DecodeError("empty key") if (len(k) < len(kPrev)) or ((len(k) == len(kPrev)) and (k <= kPrev)): raise DecodeError("unsorted keys") v, data = Decode(data) diff --git a/spec/encoding/cont.texi b/spec/encoding/cont.texi index 69bb1b5..6c1774c 100644 --- a/spec/encoding/cont.texi +++ b/spec/encoding/cont.texi @@ -11,7 +11,7 @@ LIST [ITEM0 || ITEM1 || ...] EOC @end verbatim MAP contains concatenation of @ref{Strings, STR(key)}-value pairs. Keys -@strong{must} be unique and length-first bytewise ascending ordered. +@strong{must} be non-empty, unique and length-first bytewise ascending ordered. @verbatim MAP [STR(KEY0) || ITEM0 || STR(KEY1) || ITEM1 || ... ] EOC