Bugfix/ls25001002/packed decode out of range #710
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fix a corner case causing an out range error while decoding a packed number from a
DS
.Technical notes
This PR covers a priorly not covered case in
decodeFromPacked
logic.The issue arised when we assigned a value in range
(0 .. 0,1)
to a packed in a DS. As a reference, in the specific case where the issue was first found the exact assigned value0.010000
.After the encoding process the resulting value in the
DS
was encoded truncating out the prefixing zeroes and dot (for instance in the mentioned case we kept10000
in an encoded form). This is expected and common logic for all kind of packed number serialization we support.To reverse this process during decode we rely on the target type. However the previous logic only considered cases where the dot had to be placed in the middle or after the number, not before it. Cases where the dot has to be prefixed arise whenever we decode an encoded value in range
(0 .. 0,1)
as already mentioned.This was fixed by adding a check to detect this behaviour and reverse the encoding truncation.
Related to:
Checklist:
./gradlew ktlintCheck
)../gradlew check
).docs
directory.