-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
NRG: Avoid panic on corrupted TAV file #5464
Conversation
server/raft.go
Outdated
@@ -3761,6 +3761,10 @@ func (n *raft) readTermVote() (term uint64, voted string, err error) { | |||
if err != nil { | |||
return 0, noVote, err | |||
} | |||
if len(buf) < 8 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder, should we return an error here?
Though I see that we don't handle errors from readTermVote()
anyway, beyond checking if its nil or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An error isn't really actionable in that scenario anyway as we'd still end up resetting back to term 0, in which case we'd might as well just return term 0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also let's do a test.
server/raft.go
Outdated
@@ -3761,6 +3761,10 @@ func (n *raft) readTermVote() (term uint64, voted string, err error) { | |||
if err != nil { | |||
return 0, noVote, err | |||
} | |||
if len(buf) < 8 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets add in constant above.
const termLen = 8
const termVoteLen = termLen + idLen
Then use termLen here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also be good to understand how this could have ever happened.
Maybe run full test suite and add in check when raft group goes away to check for this condition.
If the file ends up truncated somehow then we should not try to call `Uint64`, otherwise it will result in an out-of-bounds panic. Signed-off-by: Neil Twigg <neil@nats.io>
3d65afb
to
5fc2caf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - Thanks.
If the file ends up truncated somehow then we should not try to call
Uint64
, otherwise it will result in an out-of-bounds panic.Signed-off-by: Neil Twigg neil@nats.io