Live data from Hacker News

UTF-8 history (2003)

cl.cam.ac.uk

51–58 of 58 posts

Re: UTF-8 history (2003)

#51

Earlier quoted context omitted.

You can also construct malicious payloads which will DoS many implementations with architecture like that.

You can also trivially defend against that by having a max travel distance of, say, 4.

Is that guaranteed to catch all valid cases?

Re: UTF-8 history (2003)

#52
post #50
post #43

With all due respect, it seems to me that the documents contradict the claim in the initial email. Rob's initial claim is that Ken came up with UTF-8 entirely from scratch, without even looking at IBM's proposal. But Ken's oldest document from Sep 2, 1992 has his changes simply appended after the original FSS-UTF document from IBM (starting at "We define 7 byte types", as mentioned in the email), and notes the change…

One thing I was confused about. The document says there are 7 byte types, but I thought UTF-8 was variable width up to only 4 bytes. Did I misunderstand something?

Both are correct: This original UTF-8 encoding can encode values up to 2^32. But because UTF-16 encoding limits possible values to 16 planes of 64K values, unicode has a hard limit of 2^20 codepoints.

This means UTF-8 encoded values of more than 4 bytes can never represent a valid unicode codepoint even if they produce a valid 32 bit numerical value.

Re: UTF-8 history (2003)

#54

Earlier quoted context omitted.

> If not for that requirement, we would have just had UTF-8 implemented as regular VLQs. While not technically equivalent, synchronized byte stream allows a backward scanning that is beneficial for many Unicode-related algorithms. In fact synchronization is the simplest way to do that.

VLQ can also be backward scanned, since the high bit is the continuation bit. Just scan for the next cleared high bit, which marks the end of a glyph.

Provided that you know where the string boundary is, so you don't scan off the front into differently encoded data. So it can't be backward scanned for some miscellaneous encoded number.

Re: UTF-8 history (2003)

#55
post #12

"Why didn't we just use their FSS/UTF? As I remember, it was because in that first phone call I sang out a list of desiderata for any such encoding, and FSS/UTF was lacking at least one - the ability to synchronize a byte stream picked up mid-run, with less that one character being consumed before synchronization." I'm of two minds about this. On the one hand, such an ability is pretty useless in modern systems fille…

There are now encoding even more efficient than VLQ, but they blue the line in between encodings and compression algorithms. Most propose to trade efficiency of encoding 7 bit chars for ability to squeeze few thousands common Chinese characters into 16 bits. The idea I heard was that to always code in 4 bytes blocks, and use some form of delta encoding. Some variations allow for less than OlogN character position sea…

Do you have a link to this 32-bit-aligned proposal?

Re: UTF-8 history (2003)

#56

Earlier quoted context omitted.

because then you don't know when you jump in the middle of a stream and see a 11xxxxx whether it's the beginning of a valid multibyte character and you have to keep it or part of a multibyte you have to discard it same with the second encoding, if so happens that one 1xxxxxxx takes the value of 11010101 how would you know it's a multibyte start or a continuation? basically in the current solution if you read the head…

Yes, the second one is not self-synchronizing, so it's out. However, I don't see much utility in getting first-character detection from the data format itself. You're very unlikely to miss the beginning of a stream of characters in any modern system, and in the event that your medium has no error detection, it would be trivial to add a zero synchronization byte to the beginning of the field. My point is that embeddin…

> I don't see much utility in getting first-character detection ..

> .. in the event that your medium has no error detection ... add a zero synchronization byte

How would such encoding deal with non-utf8-safe editors, copy-pasting, programs truncating, then inserting previously broken sequences, etc?

Encoding obviously can't fix all errors, but it is quite useful if broken sequences are obviously broken and non-broken sequences remain valid when handling text in non-aware/non-safe applications.

I think in UTF8 two splices can generate a random character, but in a characters + splice combination, the character remains recognizable in any order and combination and a lone splice is also recognizable as an error.

Re: UTF-8 history (2003)

#57

Earlier quoted context omitted.

You can also construct malicious payloads which will DoS many implementations with architecture like that.

You can also trivially defend against that by having a max travel distance of, say, 4.

Exactly, so you arrived at the same conclusion - fixed distance so you can safely pick up stream at arbitrary position.

Re: UTF-8 history (2003)

#58

Earlier quoted context omitted.

You can also trivially defend against that by having a max travel distance of, say, 4.

Exactly, so you arrived at the same conclusion - fixed distance so you can safely pick up stream at arbitrary position.

The difference is that the distance limits would be inherent to the codec itself, rather than taking up extra space in the data stream.
Post reply on HN