Live data from Hacker News

Netstrings (1997)

cr.yp.to

11–20 of 30 posts

Re: Netstrings (1997)

#11

if (scanf("%9lu",&len) 999999999 bytes is bad */ if (getchar() != ':') barf(); buf = malloc(len + 1); /* malloc(0) is not portable */ if (!buf) barf(); if (fread(buf,1,len,stdin) Ah, the wonders of error-handling in C. Also, I wonder what's wrong with buf = malloc(len ? len : 1);

[deleted]

Re: Netstrings (1997)

#13
Making the thing that describes the bounds of an arbitrary length thing itself arbitrary length sound like an unnecessarily risky complication to me.

Especially since it only grows with the log of the thing it bounds. So, we could easily have s fixed length length field that covers all ever possible length values.

Re: Netstrings (1997)

#14
I don't like formats that look like text buy may actually contain binary data - that's only going to tempt implementations that will choke when the string actually contains arbitrary data. Would be safer to encode the length and/or separator as something more obviously binary, which will also make the thing easier to parse in low-level implementations.

Re: Netstrings (1997)

#15
I’ve near infinite respect for DJB, so I’m assuming I’ve missed something obvious here. Why is ‘,’ being used as a termination byte. Is it just a backstop? If buf[len+1] != ‘,’ then there’s a line error?

I’ve done plenty of wire protocol work, and length prefixed strings are great to work with. I’ve also been lucky that those strings were typically contained within a broader payload. To that end, I’ve not had to think about the case of many strings one after another.

Re: Netstrings (1997)

#16

I don't like formats that look like text buy may actually contain binary data - that's only going to tempt implementations that will choke when the string actually contains arbitrary data. Would be safer to encode the length and/or separator as something more obviously binary, which will also make the thing easier to parse in low-level implementations.

For this I made a tlv format, where string is encoded in byte prefixed chunks with length between 0 and 222 for final chunk and between 223 and 255 for intermediate chunks.

Re: Netstrings (1997)

#18

This is very similar to a notation occuring in Ronald Rivest's S-Expression proposal from 1996. https://people.csail.mit.edu/rivest/pubs/RL96.ver-1.0.pdf He has it as a hexadecimal length preceded by a pound sign (#), a colon, and the raw octet data.

Right, in later drafts he changed to decimal with no # prefix:

https://www.ietf.org/archive/id/draft-rivest-sexp-04.html

Re: Netstrings (1997)

#19

if (scanf("%9lu",&len) 999999999 bytes is bad */ if (getchar() != ':') barf(); buf = malloc(len + 1); /* malloc(0) is not portable */ if (!buf) barf(); if (fread(buf,1,len,stdin) Ah, the wonders of error-handling in C. Also, I wonder what's wrong with buf = malloc(len ? len : 1);

Or even:

  if (len == 0)
    return null_buffer_singleton; /* special shared representation for 0: */

Re: Netstrings (1997)

#20

Making the thing that describes the bounds of an arbitrary length thing itself arbitrary length sound like an unnecessarily risky complication to me. Especially since it only grows with the log of the thing it bounds. So, we could easily have s fixed length length field that covers all ever possible length values.

Or you could just have the standard have a "Conformance Limits" section where it says something similar to "Every implementation shall support a length field value of at least 9223372036854775807, with an unlimited number of leading zeros".

In other words, values beyond that are not forbidden by the spec, but are outside of the conformance requirements. It is a quality of implementation issue whether a given implementation handles more than required.

Post reply on HN