-
-
Notifications
You must be signed in to change notification settings - Fork 53
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
Fix panic in the JER OctetString decoder if the string isn't even length #382
Fix panic in the JER OctetString decoder if the string isn't even length #382
Conversation
Would you like adding a test case? That helps avoiding any regressions, especially if there is any refactoring coming related to performance optimizations. |
Sure, can do, I'll amend this in the coming days. |
Okay, while implementing the tests for decoding This also means, that something JER-encoded may not always round-trip without errors via some other encoding. Specifically I use rasn to convert an UPER encoded payload (sent via a bandwidth constrained LPWAN) to JER (for easier consumption), and back, which is why I noticed this. The Overview of JER doesn't actually mention constraints. It's also not clear on whether non-hex characters should just ignored or rejected. |
Constraint should not affect the encoding output in JER, while we could add still error checks and some other performance improvements based on that. You can find constraint definitions from the official standard
There should no be relationship between other codecs. OctetString allows any byte. If you encode with UPER, and decode it back with UPER, the data structure is similar and you can re-encode it with JER as well without losing values. |
Perfect, then I understood it right! Also, while writing the test, I noticed it panics for multi-byte chars as well - I'll replace that part entirely and also check if the |
6ca4b5d
to
ad78904
Compare
Updated, this also fixes issues with multi-byte characters, both for I believe I have covered the cases of excess bytes in |
Thank you for your PR! There's some clippy lints that need fixing. |
ad78904
to
2707ab2
Compare
Fixed and rebased. |
still another 😄 |
Running |
You likely need to run |
2707ab2
to
ca4c3e2
Compare
Yeah, that yielded another warning. Fixed, amended, pushed. Will you be creating a |
That's a good idea, can you make an issue for that so we don't forget. 🙂 |
Thank you for your PR! |
If the OctetString isn't of even length in the JSON file, the decoder panics with an index out of bounds error.
This PR introduces a bounds check, such that the index access
octet_string[i..=i + 1]
on line 613 doesn't panic on malformed input. Sample octet string triggering this panic:"!"
.