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

Fix Union Encoding #1861

Merged
merged 1 commit into from
Oct 2, 2021
Merged

Fix Union Encoding #1861

merged 1 commit into from
Oct 2, 2021

Conversation

jameskerr
Copy link
Member

@jameskerr jameskerr commented Oct 1, 2021

fixes #1855

When encoding a union value back into zjson, we were calling value.toString() instead of value.serialize(). The resulted in the string representation of the value rather than the json value.

In the original repro, the tags field was a union of "string", "string array", and "null". When we received the data the value was: ["CobaltStrike", "HKKFGL-AS-AP HK Kwaifong Group Limited"]. When we encoded it back it became "[CobaltStrike,HKKFGL-AS-AP HK Kwaifong Group Limited]". This resulted in bad zjson being saved. When it was read and decoded, it choked on that string value and caused the error.

A test has been added that replicated the error and confirmed that it was fixed.

When encoding a union value back into zjson, we were calling
value.toString() instead of value.serialize(). The resulted in
bad zjson being sent to the store. When it was read and decoded,
it choked and caused the error.

A test has been added that replicated the error and confirmed that
it was fixed.
@jameskerr jameskerr requested a review from mason-fish October 1, 2021 00:28
@@ -13,15 +13,17 @@ export class TypeMap implements ContainerTypeInterface {
return `|{` + typeId(keyType) + ":" + typeId(valType) + "}|"
}

create(value: [Value, Value][], typedefs) {
create(value: [Value, Value][] | null, typedefs) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Values can always be null. This was another bug the test caught. The Map and Union types are more rare and have not been battle tested as much so it makes sense these bugs are here.

@@ -18,7 +18,7 @@ export class Union implements ZedValueInterface {

serialize() {
if (isNull(this.index) || isNull(this.value)) return null
return [this.index.toString(), this.value.toString()]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The source of the bug.

Copy link
Contributor

@mason-fish mason-fish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@jameskerr jameskerr merged commit c52ee3e into main Oct 2, 2021
@jameskerr jameskerr deleted the fuse-crash branch October 2, 2021 00:31
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

Successfully merging this pull request may close these issues.

Brim App UX Error when using fuse command
2 participants