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

Binary Fields #12

Open
kevincox opened this issue Jul 2, 2022 · 4 comments
Open

Binary Fields #12

kevincox opened this issue Jul 2, 2022 · 4 comments
Assignees

Comments

@kevincox
Copy link

kevincox commented Jul 2, 2022

Right now it seems that everything is assumed to be UTF-8 as it is passed back as a Rust String. Journald is a binary protocol so it has no limitation on UTF-8. Is there a way to access the non-UTF-8 logs (like code dumps)?

@kevincox
Copy link
Author

kevincox commented Jul 2, 2022

Reading the code it looks like String::from_utf8_lossy is used which will silently corrupt binary data!

let field = String::from_utf8_lossy(b);

@yu-re-ka
Copy link
Collaborator

yu-re-ka commented Jul 5, 2022

If a field contains non-UTF-8 binary data, does it still contain a UTF-8 encoded field name?
If it's still possible to extract the field name from fields when they contain non-UTF-8 binary data, it would be good to change the type of JournalEntryFields to BTreeMap<String, Vec<u8>> and provide a method to interpret the data as UTF-8 from there. I assume the user will have to know if the data should be interpreted as UTF-8 or something else.

@kevincox
Copy link
Author

kevincox commented Jul 5, 2022

does it still contain a UTF-8 encoded field name?

All field names are [A-Z0-9]_ only. https://manpages.debian.org/testing/libelogind-dev-doc/sd_journal_print.3.en.html#DESCRIPTION

It would be good to change the type of JournalEntryFields to BTreeMap<String, Vec> and provide a method to interpret the data as UTF-8 from there.

This makes sense to me. You can always convert String to Vec<u8> for insertion and we can provide helper methods to call lossy or return an error if the field isn't UTF-8.

@yu-re-ka
Copy link
Collaborator

yu-re-ka commented Jul 5, 2022

Please have a look at #13

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