[systemd-devel] [PATCH] shared: fix utf16_to_utf8() on big endian machines

Tom Gundersen teg at jklm.no
Wed Feb 18 06:22:44 PST 2015


On Wed, Feb 18, 2015 at 3:19 PM, Martin Pitt <martin.pitt at ubuntu.com> wrote:
> Martin Pitt [2015-02-18 15:06 +0100]:
>> I couldn't quickly find a reference for EFI variables (which is the
>> main thing we are using this for), and I don't have/know a big-endian
>> EFI machine to check this on.
>
> I had a look into the official spec
> http://www.uefi.org/sites/default/files/resources/UEFI_2.4.pdf
>
> While it defines the encoding of strings in several places, like in
> "28.2.6 Strings" (page 1542), it only says that it uses the UCS-2
> subset of UTF-16. UCS-2 is defined to be big-endian only, but
> wikipedia says that in practice a lot of implementations use
> little-endian.
>
> "little-endian" and "big-endian" have no useful hits, and "UTF-16LE"
> and "UTF-16BE" have no hits in the document.
>
> On my x86_64 laptop it quite clearly uses little-endian, and the
> variables don't seem to have a BOM marker at the start to indicate
> endianness.
>
>> So if EFI variables are defined to be UTF16LE always, your patch is
>> correct.
>
> So meh -- is this defined at all?

Defined or not, it appears to be LE in practice, we didn't get any bug
reports, and there does not seem to be any way to detect LE/BE, so I
think we are best of leaving it alone and revisit the problem if any
hardware has any issues (not that I see how we can work around it).

-t


More information about the systemd-devel mailing list