Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error parsing input file: Unexpected value #25

Open
a1rb0rn3 opened this issue Nov 19, 2024 · 1 comment
Open

Error parsing input file: Unexpected value #25

a1rb0rn3 opened this issue Nov 19, 2024 · 1 comment

Comments

@a1rb0rn3
Copy link

When creating input files with a normal text editor in Linux and then trying to use your tool with those files doesn't work.
The tool exits with the error: Error parsing input file: Unexpected value: [...some garbage].

The problem is that normal text files get encoded with UTF-8 and your tool expects UTF-16LE encoding for the input files.

Solution:
A solution for the above mentioned issue is to simply convert those files to UTF-16LE.

With iconv:

iconv -f UTF-8 -t UTF-16LE input.txt > output.txt
printf '\xFF\xFE' > bom.txt
cat bom.txt output.txt > final_output.txt

With vim:

vim input.txt
:set bomb
:set fileencoding=utf-16le
:wq! output.txt

Note

The Byte Order Mark (BOM) is not needed for the input file to work as setup_var.efi strips it away anyway. However, without it, displaying the input file in the UEFI shell would be a bit ugly.

Expectations:

I don't know if you want to make your tool compatible with other file encodings, but I would somehow expect this to be mentioned in the documentation somewhere. Maybe this will help other people in future facing the same issue. It took me a while to figure out what was causing the problem :D

@datasone
Copy link
Owner

datasone commented Nov 20, 2024

Thanks for detailing the encoding problem, the origin design that assuming UTF-16LE is for recognizing UEFI shell redirected output, and I think adding the whole libiconv or encoding-rs for encoding conversion is a little too much for a UEFI application.

Some other not that important details about the design:

  • When the read from file feature was originally designed and coded, there was no fs support in uefi-rs, so reading from stdin (piped) is chosen.
  • UEFI shell will interpret file content as UTF-16, so we must use codec conversion to interprete UTF-8 bytes that are wrongly read as UTF-16.
  • Reading from file using fs seems to be a better idea, but it increases confusion (if we don't want to add codec conversion), as you must use UTF-8 for file specified in arguments (which will be read using fs api, and intepreted as UTF-8) and use UTF-16 for file specified by feeding into stdin.

I will first fix document to add text encoding information and link to this issue. And see if there will be a better design for handling both UTF-8 and UTF-16LE files.

@datasone datasone pinned this issue Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants