News for hackers. Stuff that matters.
Re:You can't just assume UTF-8 by JonChesterfield on Monday April 29, 2024 @06:12PM (#40204729)
How about assume utf-8, and if someone has some binary file they'd rather a program interpret as some other format, they turn it into utf-8 using a standalone program first. Instead of burning this guess-what-bytes-they-might-like nonsense into all the software.

We don't go "oh that input that's supposed to be json? It looks like a malformed csv file, let's silently have a go at fixing that up for you". Or at least we shouldn't, some software probably does.

Re:You can't just assume UTF-8 by ezoe on Monday April 29, 2024 @07:23PM (#40205376)
I doubt you can handle UTF-8 properly with that attitude.

The problems is, there is one very popular OS which is very hard to enforce UTF-8 everywhere, Microsoft Windows.

It's very hard to ensure all the software stack you are depending on it use Unicode version of Win32 API. Actually the native character encoding in Windows is UTF-16 so you can't just assume UTF-8. If you're writing low level code, you have to convert UTF-8 to UTF-16 and back. Even if you don't you have to ensure all the low level code you are depending on it do the same for you.

Oh and don't forget about the Unicode Normalizations. There is no THE UTF-8. There are bunch of UTF-8s with different Unicode normalizations. Apple macOS use NFD while other mostly use NFC.

These are Just some examples. When people living in ASCII world casually said "I just assume UTF-8", in reality, you still assume it's ASCII.

Re:You can't just assume UTF-8 by dgellow on Monday April 29, 2024 @08:16PM (#40205839)
I’ve been sharing it multiple times but I love it: WTF-16 spec https://simonsapin.github.io/wtf-8/#ill-formed-utf-16
Re:You can't just assume UTF-8 by int_19h on Monday April 29, 2024 @09:29PM (#40206316)
> If you're writing low level code, you have to convert UTF-8 to UTF-16 and back.

It depends. If you're writing an app, just add the necessary incantation to your manifest, and all the narrow char APIs start talking UTF-8 to you.

For a library, yeah.

Re:You can't just assume UTF-8 by ezoe on Tuesday April 30, 2024 @04:45AM (#40208633)
Don't be surprised such UTF-8 locale program will break so bad on Windows with default language set to Japanese.
Re:You can't just assume UTF-8 by int_19h on Tuesday April 30, 2024 @01:41PM (#40213703)
Why would it break? If you just assume that the system codepage is UTF-8, then sure. If you specifically say in your manifest that you want UTF-8, then Windows (10+) will give you UTF-8 regardless of which locale it is:

https://learn.microsoft.com/en-us/windows/apps/design/global...

Re:You can't just assume UTF-8 by josephg on Monday April 29, 2024 @10:03PM (#40206504)
> Actually the native character encoding in Windows is UTF-16 so you can't just assume UTF-8. If you're writing low level code, you have to convert UTF-8 to UTF-16 and back.

Yes. You should convert your strings. Thankfully, UTF-16 is very difficult to confuse with UTF-8 because they're completely incompatible encodings. Conversion is (or should be) a relatively simple process in basically any modern language or environment. And personally, I've never run into a problem where the difference between NFC and NFD mattered. (Do you have an example?). The different forms are (or should be) visually completely identical for the user - at least on modern computers with decent unicode fonts.

The largest problem with UTF-8 (and its biggest strength) is how similar it is to ASCII. It is for this reason we should consider emoji to be a wonderful gift to software correctness everywhere. Correctly handling emoji requires that your software can handle unicode correctly - because they need multi-unit encoding with both UTF-16 and UTF-8. And emoji won't render correctly unless your software can also handle grapheme clusters.

> When people living in ASCII world casually said "I just assume UTF-8", in reality, you still assume it's ASCII.

Check! If your application deals with text, throw your favorite multi-codepoint emoji into your unit testing data. (Mine is the polar bear). Users love emoji, and your software should handle it correctly. There's no excuse! Even the windows filesystem passes this test today.

Re:You can't just assume UTF-8 by kevin_thibedeau on Monday April 29, 2024 @10:46PM (#40206741)
> your software should handle it correctly. There's no excuse!

It is valid for the presentation of compound emoji can fallback to their component parts. You can't expect every platform to have an up to date database of every novel combination. A better test is emoji with color modifiers. Another good one is grandfathered symbols with both a text and emoji presentation and forcing the chosen glyph with the variant selector prefix.

Re:You can't just assume UTF-8 by josephg on Tuesday April 30, 2024 @12:53AM (#40207371)
> You can't expect every platform to have an up to date database of every novel combination.

On modern desktop OSes and smart phones, I do expect my platform to have an up-to-date unicode database & font set. Certainly for something like the unicode polar bear, which was added in 2020. I'll begrudgingly look the other way for terminals, embedded systems and maybe video games... but generally it should just work everywhere.

Server code generally shouldn't interact with unicode grapheme clusters at all. I'm struggling to think of any common, valid reason to use a unicode character database in 'normal' backend server code.

> Another good one is grandfathered symbols with both a text and emoji presentation and forcing the chosen glyph with the variant selector prefix.

I didn't know about that one. I'll have to try it out.

Re:You can't just assume UTF-8 by wheybags on Tuesday April 30, 2024 @05:23AM (#40208878)
> I'm struggling to think of any common, valid reason to use a unicode character database in 'normal' backend server code.

Case insensitive search

Re:You can't just assume UTF-8 by kevin_thibedeau on Tuesday April 30, 2024 @09:23AM (#40210710)
Unicode gets used in places that aren't continuousky updated. Good luck showing a pirate flag emoji on an embedded device like an infotainment system.
Re:You can't just assume UTF-8 by PeterisP on Tuesday April 30, 2024 @10:06AM (#40211080)
I thing being continuously updated should be tied to receiving new external content.

It's fine to have an embedded device that's never updated, but never receives new content - it doesn't matter that a system won't be able to show a new emoji because it doesn't have any content that uses that new emoji.

However, if it is expected to display new and updated content from the internet, then the system itself has to be able to get updated and actually get updated, there's no acceptable excuses for that - if it's going to pull new content, it must also pull new updates for itself.

Re:You can't just assume UTF-8 by ndriscoll on Tuesday April 30, 2024 @11:22AM (#40212012)
As the user/owner of the device, no thanks. It should have code updates if and only if I ask it to, which I probably won't unless you have some compelling reason. For the device owner, pulling new updates by itself is just a built in backdoor/RCE exploit, and in practice those backdoors are often used maliciously. I'd much rather my devices have no way to update and boot from ROM.
Re:You can't just assume UTF-8 by bee_rider on Tuesday April 30, 2024 @12:38PM (#40212999)
So like a CD player needs some way to get updates? I guess they could send out CDs with updates but approximately nobody would actually do that.
Re:You can't just assume UTF-8 by PeterisP on Thursday May 02, 2024 @03:10PM (#40240268)
The fact that we have to go as far back as CD players for a decent example illustrates my point - the "CD player" content distribution model is long dead, effectively nobody sells CD players or devices like CD players, effectively nobody distributes digital content on CDs or things like CDs (like, CD sales are even below vinyl sales) - almost every currently existing product receives content through a channel where updates could trivially be sent as well.

And if we're talking about how new products should be designed, then the "almost" goes away and they 100% wouldn't receive new content through anything like CDs, the issue transforms from an irrelevant niche (like CDs nowadays) to a nonexistent one.

Re:You can't just assume UTF-8 by kps on Tuesday April 30, 2024 @10:49AM (#40211551)
> Another good one is grandfathered symbols with both a text and emoji presentation and forcing the chosen glyph with the variant selector prefix.

I despise that Unicode retroactively applied default emoji presentation to existing symbols, breaking old text. Who the hell though that was a good idea?

Re:You can't just assume UTF-8 by eclipticplane on Tuesday April 30, 2024 @01:11AM (#40207451)
> (Mine is the polar bear).

Mine is the crying emoji.

And after enough failures in breaking the system, the 100 emoji.

Re:You can't just assume UTF-8 by josephg on Tuesday April 30, 2024 @02:26AM (#40207827)
Those are ok, but both of those emoji are represented as a single unicode codepoint. Some bugs (particularly UI bugs) only show up when multiple unicode characters combine to form a single grapheme cluster. I'd recommend something fancier.

I just tried it in gnome-terminal, and while the crying emoji works fine, polar bear or a country flag causes weird issues.

Re:You can't just assume UTF-8 by rocqua on Tuesday April 30, 2024 @04:38AM (#40208593)
Crying emoji but with a different skin color?
Re:You can't just assume UTF-8 by josephg on Tuesday April 30, 2024 @09:23AM (#40210714)
That’d work!
Re:You can't just assume UTF-8 by hnfong on Tuesday April 30, 2024 @01:55AM (#40207650)
This.

My native language uses some additional CJK chars on plane 2, and before ~2010s a lot of software had glitches beyond the basic plane of unicode. I am forever grateful for the "Gen Z" who pushed for Emojis.

Javascript's String.length is still semantically broken though. Too bad it's part of a unchangeable spec...

Re:You can't just assume UTF-8 by josephg on Tuesday April 30, 2024 @02:20AM (#40207775)
Yep. I don't use eslint, but if I did I would want a lint against any use of string.length. Its almost never what you want. Especially now that javascript supports unicode through [...str].
Re:You can't just assume UTF-8 by CryZe on Tuesday April 30, 2024 @04:50AM (#40208656)
There's Intl.Segmenter now which does Unicode Segmentation to count the amount of graphemes for example: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

Though you are right in that I don't know of a built-in way to count Unicode Scalar Values (USVs).

Re:You can't just assume UTF-8 by josephg on Tuesday April 30, 2024 @09:18AM (#40210680)
JavaScript’s recently added implementation of String[Symbol.iterator] iterates through Unicode characters. So for example, [...str] will split any string into a list of Unicode scalar values.
Re:You can't just assume UTF-8 by extraduder_ire on Tuesday April 30, 2024 @07:14AM (#40209701)
String.length is fine, since it counts UTF16 (UCS2?) code units. The attribute was only accidentally useful for telling how many characters were in a string for a long time, so people think it should work that way.
Re:You can't just assume UTF-8 by winternewt on Tuesday April 30, 2024 @07:42AM (#40209897)
There's no definition of String.length that would be the obvious right choice. It depends on the use case. So probably better to let the application provide its own implementation.
Re:You can't just assume UTF-8 by josephg on Tuesday April 30, 2024 @09:12AM (#40210641)
> So probably better to let the application provide its own implementation.

I’d be very happy with the standard library providing multiple “length” functions for strings. Generally I want three:

- Length in bytes of the utf-8 encoded form. Eg useful for http’s content-length field.

- Number of Unicode codepoints in the text. This is useful for cursor positions, CRDT work, and some other stuff.

- Number of grapheme clusters in the text when displayed.

These should all be reasonably easy to query. But they’re all different functions. They just so happen to return the same result on (most) ascii text. (I’m not sure how many grapheme clusters \0 or a bell is).

Javascript’s string.length is particularly useless because it isn’t even any of the above methods. It returns the number of bytes needed to encode the string as UTF16, divided by 2. I’ve never wanted to know that. It’s a totally useless measure. Deceptively useless, because it’s right there and it works fine so long as your strings only ever contain ascii. Last I checked, C# and Java strings have the same bug.

Re:You can't just assume UTF-8 by singpolyma3 on Tuesday April 30, 2024 @09:47AM (#40210920)
Don't you want grapheme clusters for cursor positions?

Length in encoded form can be found after encoding by checking the length of the binary content I guess.

I think for historical reasons access to codepoints can be useful, but it's rarely what one wants.

Re:You can't just assume UTF-8 by yau8edq12i on Tuesday April 30, 2024 @10:21AM (#40211220)
I don't know about Java, but the C# standard library is exceptionally well design with respect to variable byte encoding. https://learn.microsoft.com/en-us/dotnet/standard/base-types...

The built-in string.length method is useless (it returns the number of char objects) and I agree that's a problem, but the solution is also built into the language, unlike in JS.

Re:You can't just assume UTF-8 by LegionMammal978 on Tuesday April 30, 2024 @01:49PM (#40213818)
JS these days also has ways to iterate over codepoints and grapheme clusters. If you treat the string as an iterator, then its elements will be single-codepoint strings, on which you can call .codePointAt(0) to get the values. (The major JS engines can allegedly elide the allocations for this.) The codepoint count can be obtained most simply with [...string].length, or more efficiently by looping over the iterator manually.

The Intl.Segmenter API [0] can similarly yield iterable objects with all the grapheme clusters of a string. Also, the TextEncoder [1] and TextDecoder [2] APIs can be used to convert strings to and from UTF-8 byte arrays.

[0] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

[1] https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder

[2] https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder

Re:You can't just assume UTF-8 by ezoe on Tuesday April 30, 2024 @01:59AM (#40207670)
That's one good thing emoji bring to the software developers mind set.

Before emoji, if somebody open a bug report like: "Your software doesn't handle UTF-8 correctly. It doesn't handle Japanese.",

the response was "Huh? We don't bother to support Japanese. Go pound sand. Close ticket with wontfix.".

Now it's "Your software doesn't handle UTF-8 correctly. It doesn't handle emoji" and we're like "Oh shit! My software can't handle my beloved emoji!"

Re:You can't just assume UTF-8 by sharpshadow on Tuesday April 30, 2024 @05:39AM (#40208982)
Exactly I was and still am surprised how fast and wide the adoption of emojis went.
Re:You can't just assume UTF-8 by pasc1878 on Tuesday April 30, 2024 @07:04AM (#40209623)
Possibly because the major software companies made it work on phones. Thus users saw it working on many apps and complain when your app fails to do this.

Google, Apple, IBM and MS also did a lot of localisation so their code bases deal with encoding.

It is FOSS Unix software that had the ASCII mindset, probably as C and C++ string types are ASCII and many programmers want to treat strings as arrays. The MacOS and Windows APIs do take UTF as their input not char * (agreed earlier versions did not put they have provided the UTF encodings for 25 years at least.

Re:You can't just assume UTF-8 by extraduder_ire on Tuesday April 30, 2024 @07:03AM (#40209619)
> I've never run into a problem where the difference between NFC and NFD mattered. (Do you have an example?)

The main place I've seen it get annoying is searching for some text in some other text. Unless you normalize the data you're searching through the same way as you normalize your search string.

Re:You can't just assume UTF-8 by josephg on Tuesday April 30, 2024 @09:06AM (#40210601)
After reading the above comment I went looking for Unicode documentation talking about the different normalisation formats. That was a point I read that surprised me because I hadn’t ever thought of it. They said search should be insensitive to normalisation form - so generally you should normalise all text before running a search.

That’s a great tip - obvious in hindsight but one I’d never considered.

Re:You can't just assume UTF-8 by marcosdumay on Tuesday April 30, 2024 @12:02PM (#40212563)
> And personally, I've never run into a problem where the difference between NFC and NFD mattered.

You mean like opening a file by name?

Re:You can't just assume UTF-8 by magicalhippo on Monday April 29, 2024 @10:25PM (#40206631)
We make some B2B software running on Windows, integrating with customer systems. We get a lot of interesting files.

About a decade ago I wrote some utility code for reading files, where it'll try to detect BOM first, if not scan for invalid UTF-8 sequences. If none are found assume UTF-8 else assume Windows-1252. Worked well for us so far.

Still get the occasional flat file in Windows-1252 with one random field containing UTF-8, so some special handling is needed for those cases. But that's rare.

Fortunately we don't have to worry about normalization for the most part. If we're parsing then any delimiters will be one of the usual suspects and the rest data.

Re:You can't just assume UTF-8 by thayne on Monday April 29, 2024 @11:33PM (#40206958)
> Apple macOS use NFD while other mostly use NFC.

It's actually worse than that.

Older versions of mac did enforce NFD for file names, but more recent names don't, at least at the OS level. But many apple programs, such as finder _will_ use NFD. Except that it isn't even Unicode standardized NFD, it is Apple's own modified version of it. And this can cause issues when for example you create a file in finder, then search for it using `find`, and type the name of the file the exact same way, but it can't find the file because find got an NFC form, but the actual file is in NFD.

OTOH, in many applications, you don't really care about the normalization form used. For example, if you are parsing a CSV, you probably don't need to worry about if one of the cells using using a single code point or two code points to represent that accented e.

Re:You can't just assume UTF-8 by neonsunset on Tuesday April 30, 2024 @12:54AM (#40207373)
Thanks, yet another quantum of knowledge that makes one's life irreversibly ever so slightly worse. But not as bad as encryption (and learning all the terrible ways most applications have broken implementations in)
Re:You can't just assume UTF-8 by staunton on Tuesday April 30, 2024 @04:26AM (#40208507)
> most applications have broken implementations

What applications? Almost nobody writes their own implementations of encryption nowadays (nor should they). You mean openssl is "broken"?

Re:You can't just assume UTF-8 by neonsunset on Tuesday April 30, 2024 @05:07AM (#40208764)
By broken implementations I meant incorrect usage of cryptographic APIs - padding errors, nonce reuse, using weak hash functions, etc.
Re:You can't just assume UTF-8 by ezoe on Tuesday April 30, 2024 @02:02AM (#40207681)
Yeah, I know that but omit it to make my comment shorter. The world will be a slightly better if there is no macOS.
Re:You can't just assume UTF-8 by DavidPiper on Tuesday April 30, 2024 @06:02AM (#40209143)
And immeasurably better if there were no Microsoft Windows ;)

(Kidding, mostly.)

Re:You can't just assume UTF-8 by morpheuskafka on Tuesday April 30, 2024 @12:19AM (#40207213)
I got a ticket about some "folders with Chinese characters" showing up on an SMB share at work, my first thought was a Unicode issue and sure enough when you combine two UTF-8/ASCII A-z code points together as one UTF-16 code point, it will usually wind up in the CJK Common Ideographs range of Unicode. Some crappy software had evidently bypassed the appropriate Windows APIs and just directly wrote a C-style ASCII string onto the filesystem without realizing that NTFS is UTF-16.
Re:You can't just assume UTF-8 by surfingdino on Tuesday April 30, 2024 @01:33AM (#40207547)
Microsoft Windows is a source of many a headache for me as almost every other client I write code for has to deal with data created by humans using MS Office. Ordinary users could be excused, because they are not devs but even devs don't see a difference between ASCII and UTF-8 and continue to write code today as if it was 1986 and nobody needed to support accented characters.
Re:You can't just assume UTF-8 by 0xEF on Tuesday April 30, 2024 @04:48AM (#40208648)
Do you know of a resource that explains character encoding in greater detail? Just for my own curiosity. I am learning web development and boy, they brow beat UTF-8 upon us which okay, I'll make sure that call is in my meta data, but none bother to explain how or why we got to that point, or why it seems so splintered.
Re:You can't just assume UTF-8 by screwt on Thursday May 02, 2024 @09:14AM (#40235846)
(very late reply, but in case you see it)

This Joel On Software article [0] is a good starting point. Incredibly it's now over 20 years old so that makes me feel ancient! But still relevant today.

The suggestion that the web should just use utf-8 everywhere is largely true today. But we still have to interact with other software that may not use utf-8 for various legacy reasons - the CSV file example in the original article is a good example. Joel's article also mentions the solution discussed in the original article, i.e. use heuristics to deduce the encoding.

[0] https://www.joelonsoftware.com/2003/10/08/the-absolute-minim...

Re:You can't just assume UTF-8 by Comma2976 on Tuesday April 30, 2024 @05:40AM (#40208995)
Some[1] would see breaking Windows as a feature

[1]Me, surely at least 1 other

Re:You can't just assume UTF-8 by mikhailfranco on Tuesday April 30, 2024 @10:19AM (#40211193)
Some [1] may also consider working for any company/app that needs to display an emoji, to be a waste of at least one life (your life, and all your users' lives).

[1] Me, for sure.

Re:You can't just assume UTF-8 by Comma2976 on Tuesday April 30, 2024 @11:09AM (#40211845)
Some[1] may have missed the point, emojis were never supported by some[2] in their projects and they consider them to be the mark of the beast[3]

[1]you may find him at ::1

[2]HEAD~2

[3]Front-end work

Re:You can't just assume UTF-8 by zarzavat on Monday April 29, 2024 @06:27PM (#40204873)
Agreed. Continuing to support other encodings is like insisting that cars should continue to have cassette tape players.

It’s much easier to tell the people with old cassette tapes to rip them, rather than try to put a tape player in every car.

Re:You can't just assume UTF-8 by fl7305 on Monday April 29, 2024 @06:55PM (#40205115)
> It’s much easier to tell the people with old cassette tapes to rip them

I assume you mean "rip them", as in transcode to a different format?

In that case, you need a tool that takes the old input format(s) and convert them to the new format.

For text files, you'd need a tool that takes the old text files with various encodings and converts them to UTF-8.

Isn't the point of the article to describe how an engineer would create such a tool?

Re:You can't just assume UTF-8 by jcranmer on Monday April 29, 2024 @07:46PM (#40205594)
> Isn't the point of the article to describe how an engineer would create such a tool?

Honestly, no, because the tool that it's suggesting how to write isn't one that will even come close to doing a good job.

If you want to write such a tool, the first thing you need to do is to understand what the correct answer is. And to do that, you need to sample your input set to figure out what the correct answer should be for several inputs where it matters. There's unfortunately no easy way to avoid that work; universal charset detection isn't really a thing that works all that well.

Re:You can't just assume UTF-8 by fl7305 on Monday April 29, 2024 @07:50PM (#40205634)
I agree 100% on the technical issues.

But the point of the article is not the same thing as how well it achieved its goals.

Re:You can't just assume UTF-8 by javajosh on Monday April 29, 2024 @08:07PM (#40205770)
>universal charset detection isn't really a thing that works all that well.

This seems like something LLMs would be good at. A mundane use of them, but I bet they'd be really good at determining that the input has the wrong encoding. Then the program would iterate through encodings, from most probable to least, and select the one that the LLM likes the most. Granted, this means your tool will be 1GB or more. But hey, thems the breaks.

Re:You can't just assume UTF-8 by fl7305 on Monday April 29, 2024 @08:19PM (#40205874)
Yeah, that could be an interesting use of LLMs. It could at least tell you which languages might be present in the input text.

In the 1980s, we had a version of 7-bit ASCII in Sweden where the three extra Swedish vowels "åäö" were represented by "{}|".

So what might look like regular US 7-bit ASCII should be interpreted as the Swedish version if the text is in Swedish with "{}|" where "åäö" normally goes.

Re:You can't just assume UTF-8 by extraduder_ire on Tuesday April 30, 2024 @07:26AM (#40209800)
I'm glad that didn't stick around, like ¥/₩ being used for directory separators like \. I can't imagine trying to read source code with those substitutions.
Re:You can't just assume UTF-8 by 0xffff2 on Monday April 29, 2024 @07:05PM (#40205220)
A tool whose purpose is to transcode should be asking the user to select explicit input and output formats, not guessing.
Re:You can't just assume UTF-8 by fl7305 on Monday April 29, 2024 @07:09PM (#40205256)
> should be asking the user to select explicit input and output formats

It depends on the requirements.

If you're hired by a company to convert millions of old textfiles, they might want you to do it as well as possible using heuristics without any human input as a starting point.

Re:You can't just assume UTF-8 by tempaccount1234 on Tuesday April 30, 2024 @01:42AM (#40207591)
Unless the input is such garbage that asking the user is pointless (like a lot of web sources) and fixing manually is too time expensive.

It becomes easier to just use https://pypi.org/project/ftfy/ on the input.

Re:You can't just assume UTF-8 by taneq on Monday April 29, 2024 @08:41PM (#40206044)
No you don’t, they (the ones with the piles of old mixtapes) do.
Re:You can't just assume UTF-8 by fl7305 on Monday April 29, 2024 @08:54PM (#40206120)
I'm an engineer. I'm sometimes hired by they to create tools like that.
Re:You can't just assume UTF-8 by gwervc on Monday April 29, 2024 @07:11PM (#40205271)
UTF-8 uses 50% more bytes than UFT-16 to encode Chinese or Japanese texts.
Re:You can't just assume UTF-8 by arp242 on Monday April 29, 2024 @07:40PM (#40205538)
Only with "pure" CJK text in a flat text file; for most real-world situations you'll have enough ASCII text that UTF-8 will be smaller: HMTL/XML tags, email headers, things like that. I did some tests a few years back, and wasn't really able to come up with a real-world situation where UTF-16 is smaller. I'm sure some situations exist, but by and large, CJK users are better off with UTF-8.
Re:You can't just assume UTF-8 by kijin on Monday April 29, 2024 @10:18PM (#40206594)
Yep. I'm a heavy user of CJK languages and I don't give a damn about the slightly increased plaintext storage. Give me UTF-8 any day, every day. Legacy two-byte encodings can't represent all of the historical glyphs anyway, so there's no room for nationalist crap here.
Re:You can't just assume UTF-8 by jiggawatts on Tuesday April 30, 2024 @12:25AM (#40207232)
Databases tend to pack rows efficiently enough that there are scenarios where this is noticeable.
Re:You can't just assume UTF-8 by shinalin on Tuesday April 30, 2024 @04:45PM (#40216124)
Well, it's great that you did some tests a few years back, but I'm not sure how that qualifies you to make such a sweeping generalization about CJK text encoding. It's easy to dismiss UTF-16's benefits when you're only looking at a narrow slice of the real world, ignoring the vast amounts of pure CJK literature, historical archives, and user-generated content out there.
Re:You can't just assume UTF-8 by Cloudef on Monday April 29, 2024 @08:05PM (#40205752)
Only for dense CJK text, and even then if you compress the difference goes away https://utf8everywhere.org/#asian
Re:You can't just assume UTF-8 by bawolff on Monday April 29, 2024 @07:20PM (#40205348)
Which basically never matters and in any case where it actually does, gzip will make it equal again.
Re:You can't just assume UTF-8 by iraqmtpizza on Monday April 29, 2024 @07:30PM (#40205449)
zip-then-encrypt leaks information about the plaintext. if it's life or death, better not to compress at all
Re:You can't just assume UTF-8 by tnmom on Monday April 29, 2024 @07:47PM (#40205612)
Huh, never heard that before. Does it leak more information than just encrypting without zipping? Struggling to imagine how this attack works.
Re:You can't just assume UTF-8 by Jach on Monday April 29, 2024 @08:28PM (#40205950)
It's an extension of the chosen-plaintext attack, and so requires the attacker to be able to send custom text that they know is in the encrypted payload. If the unencrypted payload is "our-secret-data :::: some user specified text", then the attacker can eventually determine the contents of our-secret-data by observing how the size of the encrypted response changes as they change the text when the compression step matches up with a part of the secret data. It can be defeated by adding random-length padding after compression and before the encryption step, though.
Re:You can't just assume UTF-8 by iraqmtpizza on Monday April 29, 2024 @07:53PM (#40205664)
Encrypting without zipping doesn't leak any information about the content. You can't rule out certain byte sequences (other than by total length) just by looking at the ciphertext length.

If "oui" compresses to two bytes and "non" compresses to one byte, and then you go over them with a stream cipher, which is which:

A: ;

B: *&

Re:You can't just assume UTF-8 by lisper on Monday April 29, 2024 @08:11PM (#40205805)
This has nothing to do with compression. If you use "yes" and "no" instead of "oui" and "non" (which just happen to be three characters each) and you compress "yes" to "T" and "no" to "F" then the uncompressed text will be the leaky one.
Re:You can't just assume UTF-8 by stouset on Monday April 29, 2024 @08:56PM (#40206132)
It’s an example meant to prove the idea.
Re:You can't just assume UTF-8 by lisper on Monday April 29, 2024 @09:50PM (#40206437)
Yes, and my example was an example meant to prove the opposite idea. The point is that it is irrelevant whether you compress or not. You can leak information either way.
Re:You can't just assume UTF-8 by iraqmtpizza on Tuesday April 30, 2024 @12:41AM (#40207306)
I leak the length of my phone call and you leak:

1. the length of your phone call; and

2. what language you were speaking; oh and

3. half the words you said

(i.e. pwned)

https://web.archive.org/web/20080901185111/https://technolog...

Re:You can't just assume UTF-8 by lisper on Tuesday April 30, 2024 @02:37AM (#40207893)
> you leak [a bunch of stuff]

How? Remember, the uncompressed text gets encrypted too.

Re:You can't just assume UTF-8 by iraqmtpizza on Tuesday April 30, 2024 @02:49AM (#40207967)
It's in the article if you would bother to read it LOL. "simply measuring the size of packets without decoding them can identify whole words and phrases with a high rate of accuracy . . . [the researchers] can search for chosen phrases within the encrypted data"
Re:You can't just assume UTF-8 by lisper on Tuesday April 30, 2024 @02:58AM (#40208013)
Ah.

That article is about voice calls. Totally different topic. Nothing to do with UTF-8.

Re:You can't just assume UTF-8 by iraqmtpizza on Tuesday April 30, 2024 @03:56AM (#40208338)
You seem to struggle with abstractions. By the way, how would you have felt if you didn't have breakfast this morning? Just wondering.

Let's put our thinking caps on and consider what would happen if that same insecure voice call were encoded as little packets of text (UTF-8, even! Gasp!). Let's try to think of what might happen!

Re:You can't just assume UTF-8 by BalinKing on Monday April 29, 2024 @09:04PM (#40206184)
Cryptography noob here: I'm confused by "Encrypting without zipping doesn't leak any information about the content." Logically speaking, if we compress first and therefore "the content" will now refer to "the zipped content", doesn't this mean we still can't get any useful information?
Re:You can't just assume UTF-8 by thadt on Monday April 29, 2024 @10:14PM (#40206572)
Not OP, but 'zipping and encrypting' one thing (a file for example) does not leak information by itself. The problem comes when an adversary is able to see the length of your encrypted data, and then can see how that length changes over time - especially if the attacker can control part of the input fed to the compressor.

So if you compressed the string "Bob likes yams" and I could convince you to append a string to it and compress again, then I could see how much the compressed length changed.

If the string I gave you was something already in your data then the string would compress more than it would if the string I gave you was not already in your data - "Bob likes yams and potatoes" will be larger than "Bob likes yams likes Bob".

If the only thing I can see about your data is the length and how it changes under compression - and I can get you to compress that along with data that I hand to you - then eventually I can learn the secret parts of your data.

Re:You can't just assume UTF-8 by bawolff on Monday April 29, 2024 @10:13PM (#40206568)
Encryption generally leaks the size of the plaintext.

This is true in both the compressed and non-compressed case. However with compression the size of the plaintext depends on the contents, so the leak of the size can matter more than when not using compression.

Even without compression this can matter sometimes. Imagine compressing "yes" vs "no".

Re:You can't just assume UTF-8 by BalinKing on Tuesday April 30, 2024 @12:56PM (#40213209)
> Encryption generally leaks the size of the plaintext.

Ah, I see. Naïvely, this seems like a really bad thing for an encryption algorithm to do—is there no way around it? Like, why is encryption different from hashing in this regard?

Re:You can't just assume UTF-8 by bawolff on Tuesday April 30, 2024 @02:51PM (#40214731)
There are methods, but they are generally very inefficient bandwidth wise in the general case. The general approach is to add extra text (pad) so that all messages are a fixed size (or e.g. some power of 2). The higher the fixed size is, the less information is leaked and the less efficient it is. E.g. if you pad to 64mb but need to transmit a 1mb message, that is 63mb of extra data to transmit.

Part of the problem (afaik) is we lack good math tools to analyze the trade offs of different padding size vs how much extra privacy they provide. This makes it hard to reason about how much padding is "enough".

Another approach is adding a random amount of padding. This can be defeated if you can force the victim to resend messages (which you then average out the size of).

Hashing is different because you don't have to reconstruct the message from the hash. With encryption the recipient needs to decrypt the message eventually and get the original back. However there is no way to transmit (a maximally compressed) message in less space then it takes up.

There are special cases where this doesn't apply e.g. if you have a fixed transmission schedule where you send a sprcific number of bytes on a specific agreed upon schedule.

Re:You can't just assume UTF-8 by stouset on Monday April 29, 2024 @08:54PM (#40206125)
Yes, of course it leaks more information than encryption without compression, because that’s just encryption which doesn’t leak anything.

In an enormous number of real world cases adversaries can end up including attacker-controller input alongside secret data. In that case you can guess at secret data and if you guess correctly, you get smaller compressed output. But even without that, imagine the worst case: a 1TB file that compresses to a handful of bytes. Pretty clearly the overwhelming majority of the text is just duplicate bytes. That’s information which is leaked.

Re:You can't just assume UTF-8 by bawolff on Monday April 29, 2024 @10:08PM (#40206538)
Essentially if you zip something, repeated text will be deduplicated.

For example "FooFoo" will be smaller than "FooBar" since there is a repeated pattern in the first one.

The attacker can look at the file size and make guesses about how repetitive the text is if they know what the uncompressed or normal size is.

This gets more powerful if the attacker can insert some of their own plaintext.

For example if the plaintext is "Foo" and the attacker inserts "Fo" (giving "FooFo") the result will be smaller than if they inserted zq where there is no pattern. By making lots of guesses the attacker can figure out the secret part of the text a little bit at a time just by observing the size of the ciphertext after inserting different guesses.

Re:You can't just assume UTF-8 by bawolff on Monday April 29, 2024 @10:01PM (#40206491)
Only when the attacker can choose part of the plaintext and do the same thing over and over again with different chosen plaintexts to compare results.

Yes, there are scenarios where that matters. However the vast majority of usecases of utf-8 don't fit that or even use encryption at all.

Re:You can't just assume UTF-8 by iraqmtpizza on Tuesday April 30, 2024 @12:21AM (#40207218)
That is not the only way. There are other ways of knowing partial contents of files and changes to files, depending on the situation. If the document is a known form in which one of five boxes is checked by the sender, it's probably not hard to rule out certain selections based on the ciphertext length, if not pin down the contents exactly.
Re:You can't just assume UTF-8 by bawolff on Tuesday April 30, 2024 @02:11AM (#40207720)
I'm not sure i entirely understand your example (if there are 5 checkboxes and 1 checked, presumably length would be the same regardless which one of those are checked). However to your broader point, i agree there exist scenarios along those lines (e.g. fingerprinting known communication based on length), however most of them apply even better when not using compression.
Re:You can't just assume UTF-8 by iraqmtpizza on Tuesday April 30, 2024 @02:44AM (#40207936)
The checkbox example is completely plausible. There is no guarantee that all checkboxes lead to the same number of bytes changed in the file when checked. What if the format makes a note of the page number wherever a checkbox is checked? 1X could be two bytes and 15X would be three.

And even if the format only stored the checkbox states as a single bit each (unlikely), compression algorithms don't care. They will behave differently on different byte sequences, which can easily lead to a difference in output length.

Also, it's already been done with voice calls with no attacker-controlled data: https://web.archive.org/web/20080901185111/https://technolog...

Re:You can't just assume UTF-8 by zrm on Tuesday April 30, 2024 @06:18AM (#40209244)
The attack you're referring to is not specific to compression. It's the same class of attack that can reveal keystrokes over older versions of ssh based on packet size and timing, even on uncompressed connections. Conversely, fixed-bitrate voice streams don't have the same vulnerability as variable-bitrate encodings even though they're still compressed.

The version of your checkbox example which is vulnerable without any formal data compression is when the checkbox is encoded in a field that is only included or changes in length if the value isn't the default, common in uncompressed variable-length encodings like JSON.

Re:You can't just assume UTF-8 by iraqmtpizza on Tuesday April 30, 2024 @07:31AM (#40209839)
I'm sure that the people getting hacked care deeply about whether the attack they suffered was sui generis.

Also, zip/deflate etc was not designed to eliminate side channel leakage. Some compression schemes obviously (with padding) can mitigate leaks, but it has to be done deliberately

Re:You can't just assume UTF-8 by zrm on Tuesday April 30, 2024 @03:54PM (#40215527)
Any of it has to be done deliberately. The length of the data reveals something about its contents whether it's compressed or not.

The special concern with compression is when attacker-controlled data is compressed against secret data because then the attacker can measure the length multiple times and deduce the secret based not just on the length but on how the length changes when the secret is constant and the attacker-controlled data varies. This can be mitigated with random padding (makes the attack take many times more iterations because it now requires statistical sampling) or prevented by compressing the sensitive data and attacker-controlled data separately.

Re:You can't just assume UTF-8 by bawolff on Tuesday April 30, 2024 @09:39AM (#40210865)
If your example needs additional assumptions to be a relavent example then you should probably state them when you bring up the example.
Re:You can't just assume UTF-8 by iraqmtpizza on Wednesday May 01, 2024 @06:35AM (#40221544)
like what lol
Re:You can't just assume UTF-8 by thwarted on Tuesday April 30, 2024 @01:00AM (#40207398)
Encryption is completely unrelated to the task at hand, which is text encoding and compressing, and text encoding is not encryption.
Re:You can't just assume UTF-8 by kazinator on Monday April 29, 2024 @08:41PM (#40206043)
That's a small price to pay for:

- not having to worry about byte order;

- and cruft like surrogate pairs;

- being able to pass the text through 8 bit string representations and even manipulate it as 8 bit in certain useful ways

Add bitmapped graphics to any text, and it will dominate the size.

Size of text is just noise in the world of streaming video, terabyte drives, fiber to the home ...

Re:You can't just assume UTF-8 by neonsunset on Tuesday April 30, 2024 @12:55AM (#40207377)
This comment is factually accurate and you snowflakes should stop downvoting it.
Re:You can't just assume UTF-8 by fl7305 on Monday April 29, 2024 @06:50PM (#40205068)
> they turn it into utf-8 using a standalone program first

I took the article to be for people who would be writing that "standalone program"?

I have certainly been in a position where I was the person who had to deal with input text files with unknown encodings. There was no-one else to hand off the problem to.

Re:You can't just assume UTF-8 by 0xffff2 on Monday April 29, 2024 @07:02PM (#40205190)
In that case, you should be explicitly asking the user what the input format is.
Re:You can't just assume UTF-8 by fl7305 on Monday April 29, 2024 @07:25PM (#40205397)
> you should be explicitly asking the user what the input format is.

Me: "I'll make the program stop and ask the user."

Customer: "No. We have 10 million files. Start by using heuristics for batch processing."

Re:You can't just assume UTF-8 by Spivak on Monday April 29, 2024 @08:17PM (#40205861)
And it's usually worse, we have 10 million files coming from sources neither we nor our users control.

Or "what do you mean ask them, they barely know what a jpeg is?!"

Re:You can't just assume UTF-8 by MichaelZuo on Monday April 29, 2024 @11:49PM (#40207045)
There's someone that must be paying your invoices? Charge them extra for the extra work that needs to be done to sort things out.
Re:You can't just assume UTF-8 by Spivak on Tuesday April 30, 2024 @09:07AM (#40210606)
??? The work to use one of the many encoding guessing tools https://github.com/Joungkyun/libchardet and then get it correct for almost every document?

You just look bad if you can't do what every other software is able to do. Charging for it takes that to another level.

Re:You can't just assume UTF-8 by MichaelZuo on Tuesday April 30, 2024 @09:56AM (#40210994)
Then you don't have to worry about it since you won't get the work in the future? Someone else, with this presumably correct software, will always be able to do it for less, faster, and at a higher quality.

That's how business works...

If such a business competitor doesn't exist, then yes charge extra, and actually do the work correctly.

Re:You can't just assume UTF-8 by Spivak on Tuesday April 30, 2024 @11:23AM (#40212019)
Am I missing something here? The work is ingesting documents from uncontrolled sources that might not all be UTF-8 and handling them correctly. Using an encoding guessing tool is the means to do that. In practice since there are only a few widely-used encodings and they're not terribly ambiguous it means that everything just works and users happily use the software.

This isn't some theoretical thing, we do this at $dayjob right now not only guessing the encoding but the file-type as well so that we can make sense out of whatever garbage our users upload. Everything from malformed CSV exports form Excel to PDFs that are just JPEGs of scanned documents. It works, and it works well.

And of course it does, the files our users are handing to us work on their machines. They can open them up and look at them in whatever local software they produced them with, there's no excuse for us to be unable to do the same.

Re:You can't just assume UTF-8 by MichaelZuo on Tuesday April 30, 2024 @11:48AM (#40212388)
Then you don't need to worry about it either way?
Re:You can't just assume UTF-8 by PaulDavisThe1st on Monday April 29, 2024 @07:16PM (#40205304)
"I dunno, got it from a friend on a USB stick"
Re:You can't just assume UTF-8 by bobmcnamara on Monday April 29, 2024 @10:16PM (#40206579)
Heckin no thank you!

The FCC ULS database records are stored in a combination of no fewer than three different encodings(1252, UTF8, and something else for a handful of German names) that vary per record.

When I brought this up they said something to the effect of: it's already unicodes it has tilde letters!

Re:You can't just assume UTF-8 by eythian on Tuesday April 30, 2024 @10:32AM (#40211329)
I did once have a file that had UTF8, Windows-1252, MARC8, and VT100 (really) all mixed up in it. I think the data had gone through multiple migrations between software in its past.

I had write to my own "clean this as well as possible" thing, and it did a good enough job.

Re:You can't just assume UTF-8 by ryandrake on Monday April 29, 2024 @07:03PM (#40205194)
> We don't go "oh that input that's supposed to be json? It looks like a malformed csv file, let's silently have a go at fixing that up for you". Or at least we shouldn't, some software probably does.

What ever happened to the Robustness Principle[1]? I think the entire comment section of this article has forgotten it. IMO the best software accepts many formats and "deals with it," or at least attempts to, rather than just exiting with "Hahah, Error 19923 Wrong Input Format. Try again, loser."

1: https://en.wikipedia.org/wiki/Robustness_principle

Re:You can't just assume UTF-8 by jerf on Monday April 29, 2024 @07:12PM (#40205273)
We collectively discovered that we were underestimating the long term costs, by a lot, so its lustre has faded. This is in some sense relatively recent, so word is still getting around, as the programming world does not move as quickly as it fancies itself to.

If you'd like to see why, read the HTML 5 parsing portion of the spec. Slowly and carefully. Try to understand what is going on and why. A skim will not reveal the issue. You will come to a much greater understanding of the problem. Some study of what had happened when we tried to upgrade TCP (not the 4->6 transition, that's its own thing) and why the only two protocols that can practically exist on the Internet anymore are TCP and UDP may also be of interest.

Re:You can't just assume UTF-8 by fanf2 on Monday April 29, 2024 @07:40PM (#40205529)
RFC 9413 “maintaining robust protocols” https://datatracker.ietf.org/doc/rfc9413/ was originally titled “The Harmful Consequences of the Robustness Principle (draft-thomson-postel-was-wrong)” https://datatracker.ietf.org/doc/draft-thomson-postel-was-wr... and it has several examples
Re:You can't just assume UTF-8 by tomsmeding on Monday April 29, 2024 @07:36PM (#40205492)
Can you give a hint as to what the issue is that one should find reading a portion of the HTML 5 spec? Or is it genuinely unexplainable without experiencing something first-hand?
Re:You can't just assume UTF-8 by fl7305 on Monday April 29, 2024 @07:43PM (#40205566)
>>> the best software accepts many formats and "deals with it,"

>> We collectively discovered that we were underestimating the long term costs, by a lot, so its lustre has faded.

>> If you'd like to see why, read the HTML 5 parsing portion of the spec.

> Can you give a hint as to what the issue is that one should find reading a portion of the HTML 5 spec

I think the point was that the HTML 5 spec tries to parse all kinds of weird input instead of drawing a line in the sand and forcing the input to follow a simple format?

Re:You can't just assume UTF-8 by Spivak on Monday April 29, 2024 @08:20PM (#40205889)
It's ungodly complicated to be sure but websites from 30 years ago also still render unmodified so it's hard to say it's bad all of the time.
Re:You can't just assume UTF-8 by jerf on Monday April 29, 2024 @09:01PM (#40206162)
It isn't bad. In fact it's quite good. But it is very much a case of closing the barn door after the animals got out. You see in the standard that the effort was put to corral them back in, and I'm very glad they did, but it certainly was not free.
Re:You can't just assume UTF-8 by riffraff on Tuesday April 30, 2024 @12:30AM (#40207258)
Doesn't HTML5 prove that such an approach was more effective tho?

HTML was a massive success, while at the same time when we tried having a strict spec with XHTML, we failed miserably.

I mean, the purist in me wants strictness but it seems lousyness wins.

Re:You can't just assume UTF-8 by kelnos on Tuesday April 30, 2024 @01:26AM (#40207520)
I think the particular domain matters.

The explosion of the web happened in no small part because of how easy it was to write some HTML and get a basic, working webpage out of it. If you nested some tags the wrong way and the browser just put up an error page, rather than doing a (usually) pretty good job figuring out what you actually meant, people would get frustrated faster and not bother with it at all.

But imagine if our C/C++/Java/Rust/Go/etc. compilers were like "syntax error, but ehhhhh you probably meant to put a closing brace there, so let's just pretend you did". That would be a nightmare of bugs and security issues.

The difficulty in drawing a line in the sand and sticking to the spec, though, is that of user blame. Let's say you implement a spec perfectly -- even if you are the originator of the spec -- and then someone comes along and builds something of their own that writes out files that don't conform to the spec. Your software throws up an error and says "invalid file", but the other piece of software can read it back in just fine. Users don't know or care about specifications; they just know that your software "doesn't work" for the files they have, and the other software does. If you try to tell them that the file is bad, and the other software has a bug, they really won't care.

Re:You can't just assume UTF-8 by AnthonyMouse on Tuesday April 30, 2024 @06:54AM (#40209553)
A possible solution to this is for large organizations to be intransigent about standards compliance. If your personal mail server rejects mail that isn't well-formed, you're just being a masochist because nobody is going to change for you. If Google does it, everybody else is going to fix their stuff because otherwise they can't send to gmail.
Re:You can't just assume UTF-8 by astine on Tuesday April 30, 2024 @09:52AM (#40210954)
But imagine if our C/C++/Java/Rust/Go/etc. compilers were like "syntax error, but ehhhhh you probably meant to put a closing brace there, so let's just pretend you did". That would be a nightmare of bugs and security issues.

That's how Perl ended up the way it is.

Re:You can't just assume UTF-8 by jerf on Tuesday April 30, 2024 @10:14AM (#40211150)
It proves that engineering is hard and that everything has costs and benefits, and you can't make them go away by just ignoring them. It turns out that "being robust" had a lot of costs we didn't see.

It also shows the harmfulness of binary black and white thinking in engineering. There are choices other than "just let everyone do whatever and hope all the different things picking up the pieces do it in more or less the same way" and "rigidly specify a spec and blow up the universe at the slightest deviation". Both of those easy-to-specify choices have excessive costs. There is no escape from hard design tasks. XHTML may always have been doomed to fail, but that is not to say that HTML had to be allowed to be as loosey-goosey as it is, either.

Had a gradient of failure been introduced rather than a rigid rock wall, things very likely wouldn't have gotten as badly out of hand as they did. If, for instance, a screwed up table was specified to deliberately render in a very aesthetically unappealing manner, but not crash the entire page the way XHTML did, people would have not come to depend so much on HTML being sloppy. The resulting broken page would still be somewhat usable, but there would have been motivation to fix it, rather than the world we actually live in where it all just seemed to work.

Re:You can't just assume UTF-8 by travisb on Monday April 29, 2024 @07:20PM (#40205350)
Among other things, security became a concern.

Being lenient is all well and good when the consequences are mild. When the consequences of misinterpreting or interpreting differently to a second implementation becomes costly, such as a security exploit, then the Robustness Principle becomes less obviously a win.

It's important to understand that every implementation will try to fix-up formatting problems in their own way unique to their particular implementation. From that you get various desync or reinterpretation attacks (eg. HTTP request smuggling).

Re:You can't just assume UTF-8 by thfuran on Monday April 29, 2024 @07:27PM (#40205420)
It was a horrible idea. The real robustness principle is "Follow the spec".
Re:You can't just assume UTF-8 by nomel on Monday April 29, 2024 @07:31PM (#40205455)
I've tried telling users "sorry, your file isn't to spec", and they say "but it works with <competitor>", and that ideology flies right out the window, along with their money.
Re:You can't just assume UTF-8 by ryandrake on Monday April 29, 2024 @08:13PM (#40205825)
Exactly. "Accepting and trying" is how a lot of popular software won their market. Look at HN's favorite media player, VLC. In the past, media player software were horrible, refusing to play all but the most tightly constrained set of allowed containers/codecs. I remember spending the early 2000s trying to get Windows Media Player to play MPEGs by downloading codec packs and trying to cast secret spells into the Windows Registry. Yuck! Then along comes VLC which accepts whatever you throw at it, and that software is basically everywhere now. You can throw line noise at VLC and it will try its best to play something!
Re:You can't just assume UTF-8 by pixl97 on Monday April 29, 2024 @08:11PM (#40205807)
That's when you ask to see their file, then hack <competitors> system.
Re:You can't just assume UTF-8 by thfuran on Monday April 29, 2024 @08:56PM (#40206133)
People will pay you to do all kinds of terrible not-robust things.
Re:You can't just assume UTF-8 by Joker_vD on Tuesday April 30, 2024 @03:56AM (#40208336)
Yes, and that's why Postel's law is more of an empirical observation (a law of nature, if you will) on which software survives and which doesn't. You may dislike it but that won't make it go away.
Re:You can't just assume UTF-8 by nomel on Wednesday May 01, 2024 @02:27PM (#40227223)
I see it as the opposite, actually. They will pay you for a robust product: one that works for them. They have no care for the technical minutiae of your implementation, because they're just trying to do actually interesting things, with the help of your product. This is the customer perspective.
Re:You can't just assume UTF-8 by silotis on Monday April 29, 2024 @09:01PM (#40206164)
The trick is to enforce conformance right from the start in the first implementation of a format. Shipping a product that doesn't interop with the existing tools is a non-starter so the devs will have to fix their shit first.

As you say, unfortunately the genie cannot be put back in the bottle for formats that already have defective implementations in the wild.

Re:You can't just assume UTF-8 by riffraff on Tuesday April 30, 2024 @12:51AM (#40207360)
The problem is that unless you restrict everyone else you'll get your own product not to interact with *new" tools too.

E.g. you produce valid .wat files, but my software which also outputs those has some bits screwed up.

My program can read both .wat but yours can't, but I have 5% market share.

Your users complain they sometimes receive files your software can't read while the competitor can. Do you tell them "well that file is invalid, tell whoever sent it to you to change the software they use"?

The genie can't stay in the bottle unless you have some sort of certification authority and even that may not be enough (see USB)

Re:You can't just assume UTF-8 by thfuran on Tuesday April 30, 2024 @09:26AM (#40210746)
But the more every actor aims to follow the spec rather than reproduce everyone else's bugs, the less quickly the ecosystem devolves into a horrid tangled mess that's nigh impossible for a new entrant.
Re:You can't just assume UTF-8 by quectophoton on Tuesday April 30, 2024 @03:39PM (#40215345)
"So you're saying that I can have an advantage over everyone else if I implement all the spec features, plus one extra feature that adds convenience to our users?

And you're saying that by doing this, not only do I gain an advantage over the existing competition, but I also make it more difficult for more competitors to appear?

[takes notes]"

Re:You can't just assume UTF-8 by thfuran on Wednesday May 01, 2024 @11:21AM (#40224560)
Microsoft is a few decades ahead of you there.
Re:You can't just assume UTF-8 by jimjimjim on Monday April 29, 2024 @09:42PM (#40206398)
This is the answer.

The customer does not know. They just want it to work. They may be using something that someone else gave them. The original source system of the file may not be changeable. But most importantly, their boss just wants it to work. or else.

Re:You can't just assume UTF-8 by tedunangst on Monday April 29, 2024 @07:37PM (#40205508)
Seems like you've uploaded a jpeg. Let me OCR that into CSV for you. Hmm, no text found. Let's pass it to a multimodal LLM.
Re:You can't just assume UTF-8 by arp242 on Monday April 29, 2024 @07:43PM (#40205560)
> What ever happened to the Robustness Principle

Bush hid the facts

Re:You can't just assume UTF-8 by cesarb on Tuesday April 30, 2024 @10:16AM (#40211171)
> Bush hid the facts

For those who don't know that reference: https://en.wikipedia.org/wiki/Bush_hid_the_facts

(A text file containing only the ASCII bytes "Bush hid the facts", when opened in Windows Notepad, displays a sequence of CJK characters instead of the expected English sentence.)

Re:You can't just assume UTF-8 by david422 on Monday April 29, 2024 @08:35PM (#40206004)
> "deals with it,"

This basically loses data integrity if it's wrong though.

You might want to do that with human input if it's helpful to the user - ie user enters a phone number and you strip dashes etc. But if it's machine to machine, it should just follow the spec.

Re:You can't just assume UTF-8 by kazinator on Monday April 29, 2024 @08:47PM (#40206078)
What happened to it:

https://en.wikipedia.org/wiki/Robustness_principle#Criticism

Postel's Law doesn't pass a software engineering smell test.

The idea that software should guess and repair bad inputs is deeply flawed. It is a security threat and a source of enshittification.

Re:You can't just assume UTF-8 by chuckadams on Monday April 29, 2024 @10:02PM (#40206501)
> enshittification

I am so over this word.

Re:You can't just assume UTF-8 by kazinator on Tuesday April 30, 2024 @02:13AM (#40207735)
I put a TODO item in my calendar for December 2024 to stop using it. :)
Re:You can't just assume UTF-8 by ykonstant on Tuesday April 30, 2024 @07:08AM (#40209652)
The enshittification of enshittification was an inevitability.
Re:You can't just assume UTF-8 by jppittma on Monday April 29, 2024 @09:22PM (#40206275)
I think people have collectively decided that they want their programs stupid and predictable, rather than smart and unwieldy.
Re:You can't just assume UTF-8 by vidarh on Monday April 29, 2024 @10:21PM (#40206608)
That is fine in contexts where a wrong guess does no harm.

But that is not always the case, and e.g. silently "fixing" text encoding issues can often corrupt the data if you get it wrong.

By all means offer options of you want, but if you do flag very clearly to the user that they're taking a risk of corrupting the data unless any errors are very apparent and trivial to undo.

Re:You can't just assume UTF-8 by lamontcg on Tuesday April 30, 2024 @12:36AM (#40207287)
I've lived through dealing with non-UTF8 encoding issues and it was a truly gigantic pain in the ass. I'm much more on the side now of people who only want to deal with UTF8 and fully support software that tells any other encoding to go pound sand. The harder life gets for people who use other encodings (yes, particularly Microsoft) the more incentive they have to eventually get on board and stop costing everyone time and effort managing all this nonsense.
Re:You can't just assume UTF-8 by kelnos on Tuesday April 30, 2024 @01:22AM (#40207503)
The article addresses this, that current thinking in many places is that the robustness principle / Postel's Law maybe wasn't the best idea.

If you reject malformed input, then the person who created it has to go back and fix it and try again. If you interpret malformed input the best you can (and get it right), then everyone else implementing the same thing in the future now also has to implement your heuristics and workarounds. The malformed input effectively becomes a part of the spec.

This is why HTML & CSS are the garbage dump they are today, and why different browsers still don't always display pages exactly alike. The reason HTML5 exists is because people finally just gave up and decided to standardize all the broken behavior that was floating around in the wild. Pre-HTML5, the web was an outright dumpster fire of browser compatibility issues (as opposed to the mere garbage dump we have today).

Anyway, it's not really important to try to convince you that Postel's Law is bad; what's important is that you know that many people are starting to think it's bad, and there's no longer any strong consensus that it was ever a good thing.

Re:You can't just assume UTF-8 by SuperNinKenDo on Monday April 29, 2024 @08:25PM (#40205931)
Not every encoding can make a round trip through Unicode without you writing ad hoc handling code for every single one. There's a number of reasons some of these are still in use and Unicode destroying information is one of them.
Re:You can't just assume UTF-8 by amarshall on Monday April 29, 2024 @06:47PM (#40205040)
> some software probably does.

Browsers do, kind of https://mimesniff.spec.whatwg.org/#rules-for-identifying-an-...

Re:You can't just assume UTF-8 by 998244353 on Monday April 29, 2024 @10:29PM (#40206650)
Non-technical users don't want to do that, and won't understand any of that. That's the unfortunate reality of developing software for people.

If Excel generates CSV files with some Windows-1234 encoding, then my "import data from CSV" function needs to handle that, in one way or another. A significant number of people generate CSV files from Excel and if these people upload these files into my application and I assume an incorrect encoding, they won't care that Microsoft is using obsolete or weird defaults. They will see it as a bug in my program and demand that I fix my software. Even if Excel offers them a choice in encoding, they won't understand any of that and more importantly they don't want to deal with that right now, they just want the thing to work.

Re:You can't just assume UTF-8 by edflsafoiewq on Monday April 29, 2024 @11:25PM (#40206923)
OTOH if no one ever pushes back against entropy, your great-grandkids will still be dealing with Windows-1234 problems in 2100.
Re:You can't just assume UTF-8 by vincnetas on Tuesday April 30, 2024 @01:55AM (#40207649)
Hot to push back against entropy?

Could this work? Implement handling of ancient excel files in your SaaS product, but charge extra dollar for parsing legacy formats and provide information how to export correct files from excel next time :)

Re:You can't just assume UTF-8 by unclebucknasty on Monday April 29, 2024 @10:34PM (#40206676)
>A significant number of people generate CSV files from Excel and if these people upload these files into my application and I assume an incorrect encoding...

What if you just gave them instructions?

Re:You can't just assume UTF-8 by nkrisc on Monday April 29, 2024 @10:41PM (#40206714)
They’ll probably switch to the application that does it for them and just works, instead of the one telling them to do something they don’t really understand.
Re:You can't just assume UTF-8 by unclebucknasty on Tuesday April 30, 2024 @01:14AM (#40207461)
Selecting UTF-8 from a dropdown on the export doesn't seem too onerous an ask. If that's the differentiator between you and your competitors, then you might have bigger problems.
Re:You can't just assume UTF-8 by nkrisc on Tuesday April 30, 2024 @07:12AM (#40209680)
I have sat in on and observed many in-person usability sessions with various applications and websites.

In can tell you right now anyone reading this site is in a completely different universe of tech competency than the general public, and even professionals who aren’t tech-focused.

You would have lost many of them simply with then jumble of letters “UTF-8”.

Re:You can't just assume UTF-8 by unclebucknasty on Tuesday April 30, 2024 @08:59AM (#40210553)
Yeah, I started writing software a "while" ago. I've encountered a handful of users (and charsets) in my time.

With CSV exports, there's already a good bit of training you have to do WRT the column layout, file format, headers (or not), cell value formats, etc. There's far more lift involved in training users there than ensuring they select "UTF-8" when they select CSV.

And, there's really nothing technical about it, as they don't need to understand what "UTF-8" actually means any more than they need to understand what "CSV" stand for. It's a simple ask in a list of asks.

I weigh this against having every developer now believe they have to check/convert every character set, which can be unreliable and produce garbage, BTW. And, speaking of garbage, there are some encodings that you won't be able to convert in any case, so it would be technically impossible to preserve data integrity without pushing some requirement on the source up to the user.

So, it's about tradeoffs. And, again, if asking users to choose UTF-8 is the difference between customers choosing your app or a competitor's, then you probably need to be more worried about that than your charset encoding.

Re:You can't just assume UTF-8 by EraYaN on Tuesday April 30, 2024 @11:48AM (#40212402)
Hell we just accept xlsx and xls natively. It sucks but it solves many issues. Also causes some, but you'll never get it out of users' heads that Excel files are not a data exchange format.
Re:You can't just assume UTF-8 by unclebucknasty on Tuesday April 30, 2024 @04:55PM (#40216227)
Definitely helps. Should be able to detect the charset from the Excel metadata, at least.

Of course, if that charset uses code points not available in your app's native charset, then you're kind of back to square one (unless your use case tolerates garbled or missing data).

Re:You can't just assume UTF-8 by jimmaswell on Tuesday April 30, 2024 @09:44AM (#40210899)
I hope someday, with improved public education, we can have better users. Unlikely with Gen Z apparently having worse computer skills than the previous generation..
Re:You can't just assume UTF-8 by ghnws on Tuesday April 30, 2024 @03:34PM (#40215275)
Everyone knowing about character encodings sounds like a lot of time wasted.

Gen Z has skills in what is available and popular today, just like the previous generation had.

Re:You can't just assume UTF-8 by ghnws on Tuesday April 30, 2024 @03:31PM (#40215230)
Having worked quite a bit in b2b applications, that is exactly the kind of thing that makes customers consider other options.
Re:You can't just assume UTF-8 by unclebucknasty on Tuesday April 30, 2024 @06:54PM (#40217451)
Interesting. My experience is that business users are much more teachable and mindful than consumers, especially when working with data.
Re:You can't just assume UTF-8 by carlosjobim on Monday April 29, 2024 @10:42PM (#40206717)
I think most people would rather get in their car, drive to the ocean, board a ship and join the navy, and come back after a few years abroad - than following some instructions on how to use the computer.
Re:You can't just assume UTF-8 by unclebucknasty on Tuesday April 30, 2024 @01:20AM (#40207492)
Pretty funny, and probably some truth to that being a user sentiment.

OTOH, they have to follow some process to use the software. For just the CSV export, they already have to ensure column orders, values, formats, maybe headers, etc. Selecting UTF-8 from a dropdown seems like the easy part.

Re:You can't just assume UTF-8 by lolc on Tuesday April 30, 2024 @11:35AM (#40212205)
> they already have to ensure column orders, values, formats, maybe headers, etc.

My accrued compatibility shims disagree.

Re:You can't just assume UTF-8 by unclebucknasty on Tuesday April 30, 2024 @12:37PM (#40212980)
Sorry to hear that. You have my sympathies.
Re:You can't just assume UTF-8 by Joker_vD on Tuesday April 30, 2024 @03:51AM (#40208306)
Joining the navy and then be obliged to follow instructions on so many things you'd normally never even be ordered to do (because now you're in the Navy, sailor! and there are three ways to do any thing: the right way, the wrong way, and the Navy way, and guess which way we use here in the Navy?), just to not follow some instructions on how to use the computer... is something I can actually imagine some people doing.
Re:You can't just assume UTF-8 by vaylian on Tuesday April 30, 2024 @01:50AM (#40207626)
Plus, Excel really likes to use semicolons instead of commas for comma-separated-files. That's another idiosyncrasy that programmers need to take into account.
Re:You can't just assume UTF-8 by iggldiggl on Tuesday April 30, 2024 @03:47AM (#40208279)
I think that happens mainly in those locales where a comma is the traditional decimal separator and the dot gets used for 1000s grouping.
Re:You can't just assume UTF-8 by chopin on Tuesday April 30, 2024 @03:02PM (#40214882)
I'm German and I hate this. The icing on top: Excel separates function arguments with a semicolon in German locale, too. Got me some head scratching. Examples are separated with comma, iirc.
Re:You can't just assume UTF-8 by berkes on Tuesday April 30, 2024 @02:35AM (#40207880)
> then my "import data from CSV" function needs to handle that, in one way or another.

It doesn't. Well, maybe "another".

Your function or even app doesn't need to handle it. Here's what we did on a bookkeeping app: remove all the heuristics, edge cases, broken-csv-handling and validation from all the CVS ingress points.

Add one service that did one thing: receive a CSV, and normalize it. All ingress points could now assume a clean, valid, UTF8 input. It removed thousands of LOCs, hundreds of issues from the backlog. It made debugging easy and it greatly helped the clients even.

At some point, we offered their import runs for download, we added the [original name]_clean.csv our normalized versions. Got praise for that. Clients loved that, as they were often well aware of their internal mess of broken CVSs.

Re:You can't just assume UTF-8 by xorcist on Tuesday April 30, 2024 @06:01AM (#40209131)
The point is to separate the cleaning stage from the import stage. Having a clean utf-8 csv makes debugging import issues so much easier. And there are several well working csv tools such as the Python one, that can not only detect character encodings but also record separators and various quotation idiosyncrasies that you also need to be aware of when dealing with Microsoft Office files. Other people have already thought long and hard about that stuff so you don't have to.
Re:You can't just assume UTF-8 by kelnos on Tuesday April 30, 2024 @01:01AM (#40207408)
Solutions that require lots of unrelated people to start doing something a different way are not really solutions.
Re:You can't just assume UTF-8 by thaumasiotes on Tuesday April 30, 2024 @01:16AM (#40207470)
> We don't go "oh that input that's supposed to be json? It looks like a malformed csv file, let's silently have a go at fixing that up for you". Or at least we shouldn't, some software probably does.

Browsers used to have a menu option to choose the encoding you wanted to use to decode the page.

In Firefox, that's been replaced by the magic option "Repair Text Encoding". There is no justification for this.

They seem to be in the process of disabling that option too:

> Note: On most modern pages, the Repair Text Encoding menu item will be greyed-out because character encoding changes are not supported.

( https://support.mozilla.org/en-US/kb/text-encoding-no-longer... )

This note is logical gibberish; encoding isn't something that has to be supported by the page. Decoding is a choice by the browser!

Re:You can't just assume UTF-8 by shiomiru on Tuesday April 30, 2024 @03:17AM (#40208116)
It seems the decision was made in the name of security:

https://hsivonen.fi/no-encoding-menu/

> Supporting the specific manually-selectable encodings caused significant complexity in the HTML parser when trying to support the feature securely (i.e. not allowing certain encodings to be overridden). With the current approach, the parser needs to know of one flag to force chardetng, which the parser has to be able to run in other situations anyway, to run.

> Elaborate UI surface for a niche feature risks the whole feature getting removed

> Telemetry [...] suggested that users aren’t that good at choosing correctly manually.

In other words, it's trying to protect users from themselves by dumbing down the browser. (Never mind that people who know what they are doing have probably also turned off telemetry...)

Re:You can't just assume UTF-8 by thaumasiotes on Tuesday April 30, 2024 @05:06AM (#40208762)
Wow. That writeup is insane.

>> Supporting the specific manually-selectable encodings caused significant complexity in the HTML parser when trying to support the feature securely (i.e. not allowing certain encodings to be overridden).

There's no explanation of why you'd want this, or why it's security-relevant.

(Farther down, there's a mention of self-XSS, which definitely isn't relevant.)

>> Elaborate UI surface for a niche feature risks the whole feature getting removed

They've already removed the whole feature. That was easier to do after they mostly disabled it, not harder.

>> Telemetry showed users making a selection from the menu when the encoding of the page being overridden had come from a previous selection from the menu.

That would be an example of "working as expected". The removal of the ability to do this is the problem that disabling the encoding menu causes! Under the old, correct approach, you'd guess what the encoding was until you got it right. Under the new approach, the browser guesses for you, and if the first guess is wrong, screw you.

Re:You can't just assume UTF-8 by n_plus_1_acc on Tuesday April 30, 2024 @03:13AM (#40208092)
Probably because most websites now send a correct encoding header or meta Tag, so the user changing can only make it wrong. (Assuming no encoding header is wrong, which happens in reality)
Re:You can't just assume UTF-8 by layer8 on Tuesday April 30, 2024 @07:39AM (#40209884)
It does happen a lot that old text content in non-UTF-8 encoding is mistakenly served explicitly marked as UTF-8. It is precisely in such circumstances that the Repair Text option is useful.