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

Handle UTF-8 errors when reading PBOs #34

Open
BrettMayson opened this issue Apr 27, 2019 · 17 comments
Open

Handle UTF-8 errors when reading PBOs #34

BrettMayson opened this issue Apr 27, 2019 · 17 comments
Labels
bug Something isn't working

Comments

@BrettMayson
Copy link
Contributor

BrettMayson commented Apr 27, 2019

thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: FromUtf8Error { bytes: [82, 80, 95, 67, 111, 109, 109, 97, 110, 100, 115, 32, 151, 32, 107, 111, 112, 105, 97, 46, 104, 112, 112], error: Utf8Error { valid_up_to: 12, error_len: Some(1) } }', src/libcore/result.rs:997:5

Comes from read_cstring , one file I know that causes it is @rhsusaf/addons/rhsusf_c_radio.pbo while trying to use PBO::read or armake2 unpack

@BrettMayson BrettMayson changed the title read_cstring doesn't support full UTF-8 read_cstring UTF-8 error Apr 27, 2019
@BrettMayson
Copy link
Contributor Author

It's being caused by an em dash (—) in the filename RP_Commands — kopia.hpp

@BrettMayson
Copy link
Contributor Author

BrettMayson commented May 3, 2019

I determined this was being caused by the PBO being encoded with Windows-1252 filenames. The em dash (—) character is not able to be opened in a UTF-8 context and causes this bug.

@Krzmbrzl
Copy link
Contributor

Krzmbrzl commented May 3, 2019

So is this even a real bug in armake then? 🤔

@BrettMayson
Copy link
Contributor Author

Yes, it can be handled

@Krzmbrzl
Copy link
Contributor

Krzmbrzl commented May 3, 2019

But only if the encoding has some kind of identifying header, right? Is this the case?

@BrettMayson
Copy link
Contributor Author

It can also be dropped by doing a lossy conversion to UTF-8, that is what I did for a workaround

@Krzmbrzl
Copy link
Contributor

Krzmbrzl commented May 3, 2019

By that I assume you mean decoding the input with UTF-8 and throwing away all invalid bits and pieces that come up during that conversion?

@BrettMayson
Copy link
Contributor Author

Yes

@Krzmbrzl
Copy link
Contributor

Krzmbrzl commented May 3, 2019

Not sure if that is a good practice that should be applied in the general case. If this messes something up, then the user might get really confused because the error message complains about character sequences that don't exist in the original.
Or even worse: armake doesn't even detect the error but some of the scripts messed up. This error would then be detected in Arma leading to some really awkward bugs.

I think it would be better to error out on such things. At least by default. I think we could add another option that can be set to force the lossy conersion in such cases.

@KoffeinFlummi
Copy link
Owner

Handling this sloppily could lead to problems. Different tools handling this issue differently could lead to those tools calculating different hashes when signing or verifying PBOs, so a warning should be shown at least. Obviously it should be possible to handle it in some way since it would very simple to prevent unpacking of PBOs otherwise.

@KoffeinFlummi KoffeinFlummi changed the title read_cstring UTF-8 error Handle UTF-8 errors when reading PBOs May 13, 2019
@KoffeinFlummi KoffeinFlummi added the bug Something isn't working label May 13, 2019
@Soldia1138
Copy link
Contributor

Soldia1138 commented May 28, 2019

We could add multiple tries to read the PBO in different encodings (Try UTF-8, error -> Try another).

As an alternative we could do a lossy conversion if the normal reading fails and somehow mark the file, like adding a fat comment on top

@Krzmbrzl
Copy link
Contributor

I think the problem is to detect whether decoding with the current charset has failed. It's not like it woul throw exceptions when attempting to use the wrong charset.
You'd have to actually go through the decoded content and try to check whether this looks like proper text/code or whether that is rubbish...

@BrettMayson
Copy link
Contributor Author

Using non lossy utf-8 will fail, at least with the RHS file from the original comment

@Krzmbrzl
Copy link
Contributor

Krzmbrzl commented May 29, 2019

Maybe this here could be handy for this: https://github.com/lifthrasiir/rust-encoding
We could iterate all charets that are available in that library and see if the decoding works properly. If not (from the README I assume that this library does also throw errors if the decoding fails), try the next one (and so on).

@Soldia1138
Copy link
Contributor

That would be exactly what I meant. Good catch.

As I‘m doing a mass sign of files, I can say that probably 3-5% of all files (roughly 70GB of pbos) have non-UTF8 encoding.
So it would be very beneficial, if armake2 would automatically switch through encodings if one fails.

I‘m wondering how armake1 handles this. Used that until now and it never throws any errors on this.

@Reidond
Copy link

Reidond commented Jul 21, 2019

Another error but with packing
error: Failed to write PBO: Windows stdio in console mode does not support writing non-UTF-8 byte sequences

@ArwynFr
Copy link

ArwynFr commented May 3, 2021

The error seems also to occur when reading an LZSS compressed PBO

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants