Skip to content

Avoid corruption when deserializing booleans#22152

Merged
jasontedor merged 1 commit intoelastic:masterfrom
jasontedor:read-boolean-corruption
Dec 14, 2016
Merged

Avoid corruption when deserializing booleans#22152
jasontedor merged 1 commit intoelastic:masterfrom
jasontedor:read-boolean-corruption

Conversation

@jasontedor
Copy link
Copy Markdown
Member

@jasontedor jasontedor commented Dec 13, 2016

Today we write 0x00 or 0x01 for false or true when serializing a boolean
(and 0x02 for null when serializing an optional boolean) but we
deserialize any non-zero byte to true (except when deserializing an
optional boolean in which case we deserialize 0x02 to null, 0x01 to
true, and any other non-zero byte to false). This too easily allows
corruption into the stream. Instead, we should mark the stream as
corrupted and stop deserializing. This catches when we try to
deserialize something as a boolean that is not a boolean.

Copy link
Copy Markdown
Member

@nik9000 nik9000 left a comment

Choose a reason for hiding this comment

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

Sounds like a good idea to me.

Today we write 0x00 or 0x01 for false or true when serializing a boolean
(and 0x02 for null when serializing an optional boolean) but we
deserialize any non-zero byte to true (except when deserializing an
optional boolean in which case we deserialize 0x02 to null, 0x01 to
true, and any other non-zero byte to false). This too easily allows
corruption into the stream. Instead, we should mark the stream as
corrupted and stop deserializing. This catches when we try to
deserialize something as a boolean that is not a boolean.
@jasontedor jasontedor force-pushed the read-boolean-corruption branch from 77f7be9 to a378b5a Compare December 14, 2016 01:09
@jasontedor jasontedor merged commit 0d195f1 into elastic:master Dec 14, 2016
jasontedor added a commit that referenced this pull request Dec 14, 2016
Today we write 0x00 or 0x01 for false or true when serializing a boolean
(and 0x02 for null when serializing an optional boolean) but we
deserialize any non-zero byte to true (except when deserializing an
optional boolean in which case we deserialize 0x02 to null, 0x01 to
true, and any other non-zero byte to false). This too easily allows
corruption into the stream. Instead, we should mark the stream as
corrupted and stop deserializing. This catches when we try to
deserialize something as a boolean that is not a boolean.

Relates #22152
@jasontedor jasontedor deleted the read-boolean-corruption branch December 14, 2016 01:10
@jasontedor
Copy link
Copy Markdown
Member Author

Thanks @nik9000 and @jaymode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants