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

NRG: Avoid panic on corrupted TAV file #5464

Merged
merged 1 commit into from
May 22, 2024
Merged

Conversation

neilalexander
Copy link
Member

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

@neilalexander neilalexander requested a review from a team as a code owner May 22, 2024 08:48
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 {
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

@derekcollison derekcollison left a 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 {
Copy link
Member

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.

Copy link
Member

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>
Copy link
Member

@derekcollison derekcollison left a comment

Choose a reason for hiding this comment

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

LGTM - Thanks.

@derekcollison derekcollison merged commit 7672774 into main May 22, 2024
4 checks passed
@derekcollison derekcollison deleted the neil/readtermvote branch May 22, 2024 13:08
wallyqs added a commit that referenced this pull request Jun 5, 2024
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.

3 participants