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

Stepping off end of collection when desired key is not in the payload but other ignored keys are present #82

Closed
rubixhacker opened this issue Oct 20, 2022 · 1 comment · Fixed by #85 or #88
Labels
bug Something isn't working

Comments

@rubixhacker
Copy link

  • Version: 0.5.2
  • All platforms

When decoding a nested structure if the desired key is not present in the structure and ignoreUnknownKeys is set to true, MsgPackDecoder will step outside the bounds of the nested structure and continue searching for the key in the parent structure until it hits the end of the payload. Causing Kotlin Serialization to report required keys are missing in the parent structure.

As an example, take the given json encoded payload:

{
    "a": 1,
    "b": {
        "d": 2,
        "e": 3
     },
     "f":4
}

And the following Kotlin serializable class

@Serializable
data class Example(val a: Int, val b: Example.Child, val f: Int) {
     
     @Serializable
     data class Child(val c: String? = null)
}

ClassMsgPackDecoder when trying to find "c" will start a recursive call to BasicMsgPackDecoder.decodeElementIndex which if ignoreUnknownKeys is true will continue recursively calling BasicMsgPackDecoder.decodeElementIndex until it either finds "c" or in this case hits the end of the payload. Kotlin serialization will report that it could not find the required key "f"

ClassMsgPackDecoder needs to get the result of BasicMsgPackDecoder.decodeElementIndex so that it can properly increment decodedElements

@rubixhacker rubixhacker added the bug Something isn't working label Oct 20, 2022
@esensar
Copy link
Owner

esensar commented Oct 20, 2022

Thank you for reporting this and thank you for taking your time to investigate the issue.

Feel free to open a PR if you wish to fix this yourself. If not, I will take it on as soon as I have the time.

esensar added a commit that referenced this issue Feb 13, 2023
If `ignoreUnknownKeys` flag is on, reading could overflow to further
structures and cause issues when these structures need to be parsed.

This closes #87
This fixes #82
esensar added a commit that referenced this issue Feb 13, 2023
If `ignoreUnknownKeys` flag is on, reading could overflow to further
structures and cause issues when these structures need to be parsed.

This closes #87
This fixes #82
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
2 participants