Re: Binary S-expressions Lassi Kortela 17 Sep 2019 12:05 UTC

> A tangential but related issue is that I shy away from using read and
> write for "protocols" where possible due to the frequent presence of
> vendor extensions that allow for executing arbitrary code in read -
> which isn't a problem in trusted environments, but still seems like an
> unnecessary danger that could lead to an exploit escalating... I've
> ended up writing ad-hoc binary representations for protocol use when it
> would have been far nicer to use read and write. An untrusted-data-safe
> binary sexpression format SRFI would be most welcome with me - but I'd
> like it in its own SRFI rather than a persistence one, as I'd use it for
> protocols more than for persisting :-)

Thanks for the support, Alaric :) Once again, I agree with all your
points of view.

Almost forgot, here is Rivest's Internet Draft for portable
S-expressions: <http://people.csail.mit.edu/rivest/Sexp.txt>. Those are
text-based, but permit bytevectors (octet strings) to be encoded with a
length prefix, similar to rain1's encoding. The landing page with links
to C code: <http://people.csail.mit.edu/rivest/sexp.html>.

I would still prefer a binary encoding for interchange, since a text
encoding using length prefixes is not really human-readable or editable.
Also, people tend to open text files in text editors, which causes all
the usual problems with character encodings and whitespace to start
spreading. If we make binary S-expressions with the same data model as
text ones, it'll be trivial to convert back and forth, so people can
just convert to text for editing and inspection.

If there is interest, I can write a spec about such an encoding, and
solicit feedback. The basics are extremely easy to do with varints, as
demonstrated. Intricate data types like floats, timestamps, etc. are
harder, and could be left out, or if not, people like John know a lot
more about those than I do.

I'd like to have an encoding that has enough range that it can also be
used seamlessly from Common Lisp, Clojure and Emacs Lisp. In fact, I'd
like to have command-line program that converts between all the
different text/binary S-expression representations. You could just pipe
things to it as you went about your daily work.

The encoders/decoders could have an option for how to convert nil/#f/().