keybase / saltpack

a modern crypto messaging format
https://saltpack.org/
BSD 3-Clause "New" or "Revised" License
989 stars 62 forks source link

Fix concurrent use of basex.Encoding (Crash, hang or corrupted data) #68

Closed gabriel closed 5 years ago

gabriel commented 5 years ago

The encoder will fail if you try to use it concurrently because the Encoding is keeping a "scratchInt" variable that it is mutating on decode. This is particularly gnarly because it can randomly cause the decoded data to be changed (if it doesn't crash). I've also seen it just hang the runtime as well.

I added a test case which shows a crash on concurrent use, and a fix which removes use of a scratchInt.

Nothing in the Encoding struct should be changed on encode or decode since it is a shared value.

akalin-keybase commented 5 years ago

cc @maxtaco, merging